5

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?

  • 1
    solution found,must use -t "." on sort and sort column after . – elbarna Oct 14 '14 at 18:34
7

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.

| improve this answer | |
  • yes it does – artm Oct 14 '14 at 18:43
  • 1
    No,only LC_COLLATE no,but LC_ALL works fine – elbarna Oct 14 '14 at 18:44
  • add -l flag to xargs – artm Oct 14 '14 at 18:46
  • Solution found...find . |grep -v scripts|xargs ls -lhd works without sort,the problem was utf8! – elbarna Oct 14 '14 at 18:50
  • 1
    Another problem with that pipeline is that the result of sort is ignored because ls sorts its output by default. To actually have it display results in the order that sort produces ls could be given -U flag. – artm Oct 14 '14 at 18:53
0

Most simply use export LC_ALL=C,make the script with ls,sort,etc and then return to you favourite LC,in my case UTF8.

| improve this answer | |
  • 2
    Instead of export LC_ALL, it is probably preferable to set collation order only for that particular ls command thus: LC_COLLATE=C ls -nl --time-style=long-iso – Toby Speight Sep 3 '15 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.