In all three cases below (folder, files with zeros only and files with 1), I expect the order to be C-A-B and not A-B-C. Why are leading zeros not considered? It seems to be taking contiguous numbers as a whole entity (thus zero irrelevant) and not as independent characters.
1 Answer
That looks like the "natural sort of (version) numbers" as done by ls -v
and sort -V
(GNU). The result looks a bit odd here, but the point is to sort 1.1
< 1.2
< 1.11
< 1.12
. That is, to look at each sequence of digits as a number instead of individual characters. That naturally means leading zeroes are not significant.
$ touch '00 - A' '000 - B' '0 - C'
$ /bin/ls -v1
00 - A
000 - B
0 - C
Lacking that, the locale settings would of course also affect sorting:
$ LC_ALL=C /bin/ls -1
0 - C
00 - A
000 - B
$ LC_ALL=en_US.UTF-8 /bin/ls -1
000 - B
00 - A
0 - C
You'll have check if the program you're using has any documentation on or settings to modify how it sorts.