Linux and Unix file wildcards

I am looking to get a list of files in a directory in Linux, starting with a capital letter. On Unix, it's simple

ls [AZ] *

On Linux, however, I see matches that do not seem to be case sensitive:

=> ls
A.txt  b.txt  B.txt  c.txt  C.txt

=> ls [A]*
A.txt

=> ls [AB]*
A.txt  B.txt

=> ls [ABC]*
A.txt  B.txt  C.txt


  => ls [AC] * A.txt b.txt B.txt c.txt C.txt

=> ls [b]*
b.txt


  => ls [ac] * A.txt b.txt B.txt c.txt

Running the same commands on the Unix side works as I expected. Is Linux always like this? It's easy enough to get around this with awk, so I'm not looking for a solution this way, but I wonder if I have noticed this before. Thanks in advance.

+4
source share
1 answer

, : nocasematch nocaseglob LC_COLLATE ( , [-] ..)

$ shopt extglob nocasematch nocaseglob
extglob         off
nocasematch     off
nocaseglob      off


$ printf "%s\n" a A b B c C | sort
a
A
b
B
c
C

, [A-C] b c, a, [a-c] A, C.

$ printf "%s\n" a A b B c C | LC_COLLATE=C sort
A
B
C
a
b
c

.

$ LC_COLLATE=C ls [A-C]*

, (ls), .

EDIT: , , LC_COLLATE, .

$ export LC_COLLATE=C
$ ls [A-C]*
+7

Source: https://habr.com/ru/post/1674313/


All Articles