You are not logged in.

#1 2012-05-20 20:06:40

nsmartt
Member
Registered: 2012-05-19
Posts: 7

[SOLVED] Hidden Files/Directories First with ls?

I don't know how to word what I want. So here's an example:
$ ls ~
.purple downloads .bashrc color.sh

Where .purple and downloads are directories.
I remember adding something to my .bashrc (in the distant past) to change the default behavior, but I believe it was an environment variable or something (as opposed to an option with ls).

Does anyone have information regarding this?


Edit:
The behavior I'm after is for directories and files beginning with a period to be shown first- as if alphabetically sorted but with "." being treated as being before a and 1.
Adding the following to .bashrc:
export LANG=PPOSIX
accomplishes this, but I don't really understand why. It also isn't the method I used the last time.

So my question is "Is there another way to do this, and, if not, can anyone explain how this works?"

Last edited by nsmartt (2012-05-20 21:36:39)

Offline

#2 2012-05-20 20:22:05

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: [SOLVED] Hidden Files/Directories First with ls?

The thing you added to .bashrc was an alias. If you want more information, run

man alias
man ls

maybe in combination with some search engine.

Offline

#3 2012-05-20 20:37:25

nsmartt
Member
Registered: 2012-05-19
Posts: 7

Re: [SOLVED] Hidden Files/Directories First with ls?

/dev/zero wrote:

The thing you added to .bashrc was an alias. If you want more information, run

man alias
man ls

maybe in combination with some search engine.

Thanks, but it wasn't an alias. That's why I mentioned that ls lacks an option to do this.

Edit:
I've tried searching for this (I found it the last time I was looking for this), but all I found was a thread about Fedora. Apparently, adding "export LANG=POSIX" works on Fedora, but running "LANG=POSIX ls" in terminal doesn't work as expected.
This is where I got with this edit before I decided to try adding "export LANG=POSIX" to my .bashrc (Which works, even though "LANG=POSIX ls" doesn't).
Will this cause any trouble in the long term since LANG exists/is being overwritten?

Edit 2:
export LANG=POSIX is not what I added the first time.

Last edited by nsmartt (2012-05-20 20:48:20)

Offline

#4 2012-05-20 20:54:05

xangelux
Member
Registered: 2010-05-29
Posts: 73

Re: [SOLVED] Hidden Files/Directories First with ls?

You can do it by ussing the flag --group-directories-first

ls -la --group-directories-first

If you want this behavior always, you have to create an Alias in your .bashrc

Offline

#5 2012-05-20 20:58:34

nsmartt
Member
Registered: 2012-05-19
Posts: 7

Re: [SOLVED] Hidden Files/Directories First with ls?

xangelux wrote:

You can do it by ussing the flag --group-directories-first

ls -la --group-directories-first

If you want this behavior always, you have to create an Alias in your .bashrc

Thanks, but I'm talking about files and directories preceded by a . being shown first, not directories first in general.

Offline

#6 2012-05-20 21:22:49

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Hidden Files/Directories First with ls?

nsmartt wrote:

I don't know how to word what I want. So here's an example:
$ ls ~
.purple downloads .bashrc color.sh

On my box 'ls' doesn't show hidden files / directories at all, so I think you are using some kind of an alias.
Run

type -a ls

to make sure.

$ ls -A
.1  .a	.d  .z	10  11	21  aa	ab  da
$ ls -Al
total 8
-rw-r--r-- 1 karol users    0 05-20 23:10 .1
-rw-r--r-- 1 karol users    0 05-20 23:10 .a
drwxr-xr-x 2 karol users 4096 05-20 23:10 .d
-rw-r--r-- 1 karol users    0 05-20 23:10 .z
-rw-r--r-- 1 karol users    0 05-20 23:10 10
-rw-r--r-- 1 karol users    0 05-20 23:10 11
-rw-r--r-- 1 karol users    0 05-20 23:10 21
-rw-r--r-- 1 karol users    0 05-20 23:10 aa
-rw-r--r-- 1 karol users    0 05-20 23:10 ab
drwxr-xr-x 2 karol users 4096 05-20 23:10 da

I'm using

export LC_COLLATE="C"

in my .bashrc.
Using different collation gives different results:

$ LC_COLLATE="pl_PL.UTF-8" ls -A
.1  10	11  21	.a  aa	ab  .d	da  .z

Offline

#7 2012-05-20 21:36:17

nsmartt
Member
Registered: 2012-05-19
Posts: 7

Re: [SOLVED] Hidden Files/Directories First with ls?

karol wrote:
nsmartt wrote:

I don't know how to word what I want. So here's an example:
$ ls ~
.purple downloads .bashrc color.sh

On my box 'ls' doesn't show hidden files / directories at all, so I think you are using some kind of an alias.
Run

type -a ls

to make sure.

$ ls -A
.1  .a	.d  .z	10  11	21  aa	ab  da
$ ls -Al
total 8
-rw-r--r-- 1 karol users    0 05-20 23:10 .1
-rw-r--r-- 1 karol users    0 05-20 23:10 .a
drwxr-xr-x 2 karol users 4096 05-20 23:10 .d
-rw-r--r-- 1 karol users    0 05-20 23:10 .z
-rw-r--r-- 1 karol users    0 05-20 23:10 10
-rw-r--r-- 1 karol users    0 05-20 23:10 11
-rw-r--r-- 1 karol users    0 05-20 23:10 21
-rw-r--r-- 1 karol users    0 05-20 23:10 aa
-rw-r--r-- 1 karol users    0 05-20 23:10 ab
drwxr-xr-x 2 karol users 4096 05-20 23:10 da

I'm using

export LC_COLLATE="C"

in my .bashrc.
Using different collation gives different results:

$ LC_COLLATE="pl_PL.UTF-8" ls -A
.1  10	11  21	.a  aa	ab  .d	da  .z

I was using an alias to do ls -A by default. I forgot to say ls -A because I've gotten so used to it. My fault.
LC_COLLATE is exactly what I was trying to find. Thanks so much.
Time to find out what LC_COLLATE is.

Offline

#8 2012-05-21 14:43:24

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Hidden Files/Directories First with ls?

nsmartt wrote:

Time to find out what LC_COLLATE is.

I found some info here: http://pubs.opengroup.org/onlinepubs/79 … nvvar.html

LC_COLLATE
    This variable determines the locale category for character collation. It determines collation information for regular expressions and sorting (...)

Offline

Board footer

Powered by FluxBB