Sort and ls — why aren’t capitalized letters sorted first

localelssort

I want a sorting like this, with capitalized letters before lowercase:

-rw-r--r--.  1 0 0    183 2014-10-14 20:17 ./CHECKSUMS.md5
-rw-r--r--.  1 0 0    185 2014-10-14 20:17 ./CHECKSUMS.asc
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:01 ./a
-rw-------.  1 0 0 464140 2013-12-16 19:11 ./a/pam-1.1.8-x86_64-2mg.txz
drwxr-xr-x.  2 0 0   4096 2014-10-14 19:55 ./b
-rw-------.  1 0 0 464140 2014-10-14 19:55 ./b/pam-1.1.8-x86_64-2mg.txz
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./c
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./d
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./e
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./f
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./g

I use this command:

find -L . -print  | sort -d | xargs ls -nld --time-style=long-iso

and result is:

drwxr-xr-x. 29 0 0   4096 2014-10-14 20:17 .
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:01 ./a
-rw-------.  1 0 0 464140 2013-12-16 19:11 ./a/pam-1.1.8-x86_64-2mg.txz
drwxr-xr-x.  2 0 0   4096 2014-10-14 19:55 ./b
-rw-------.  1 0 0 464140 2014-10-14 19:55 ./b/pam-1.1.8-x86_64-2mg.txz
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./c
-rw-r--r--.  1 0 0    183 2014-10-14 20:17 ./CHECKSUMS.md5
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./d
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./e
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./f
drwxr-xr-x.  2 0 0   4096 2014-10-14 18:00 ./g

How can I get the sort order I want?

Best Answer

Check your environment variable LC_COLLATE. The easiest thing will be to use the command locales. If you want, you can set it to a different value. For example, you can do (assuming bash)

export LC_COLLATE="C"

and that should fix your issue.

Related Question