You are not logged in.

#1 2015-08-15 08:45:06

dice
Member
From: Germany
Registered: 2014-02-10
Posts: 413

ls sort numbers naturally but stay case insensitive

Is it possible to have the ls command sort the entries in natural order if they start with numbers but still be case insensitive if they start with characters?

ls man page wrote:

-v     natural sort of (version) numbers within text

But this not only changes sorting for numbers but also how other letters are handled.

$ ls -l
total 0
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:25 01-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:25 02-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:25 03-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:26 10-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:26 11-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:26 1-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 a
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 A
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 b
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 B
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 c
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 C
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 d
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 D

1-file is placed after the 0x-files. I want it to be right between 01 and 02.
The non numeric ones are sorted case insensitive.

$ ls -lv
total 0
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:25 01-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:26 1-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:25 02-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:25 03-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:26 10-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:26 11-file
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 A
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 B
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 C
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 D
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 a
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 b
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 c
-rw-r--r-- 1 lukas lukas 0 15. Aug 10:27 d

Here the numbers are sorted the way I'd like but now all uppercase letters are placed before the lowercase letters which I don't want.

Is this affected by the LC_COLLATE setting? If so, where can I find documentation on customizing it? The wiki section seems not very helpful in this case.

$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_US.utf8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_US.utf8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

I put at button on it. Yes. I wish to press it, but I'm not sure what will happen if I do.  (Gune | Titan A.E.)

Offline

#2 2015-08-15 08:52:45

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

Re: ls sort numbers naturally but stay case insensitive

$ LC_COLLATE=C ls -v
00  01  1  02  2  3

but

$ LC_COLLATE=C ls -v
00  01  1  02  2  3  A  B  C  a  b  c

Last edited by karol (2015-08-15 08:53:36)

Offline

#3 2015-08-15 11:46:03

dice
Member
From: Germany
Registered: 2014-02-10
Posts: 413

Re: ls sort numbers naturally but stay case insensitive

Okay, so what I'd like is a sorting like this:

00 01 1 02 2 3 a A b B c C

It seems that

LC_COLLATE="en_US.utf8"

makes the aA part possible but when using the -v option it behaves like LC_COLLATE=C where all uppercase letters are first and then all lowercase letters.


I put at button on it. Yes. I wish to press it, but I'm not sure what will happen if I do.  (Gune | Titan A.E.)

Offline

Board footer

Powered by FluxBB