I have the following files:
$ ls
_010.txt 01.txt 10.txt 1.txt 3.txt mov001 mov00a _mov00A mov00B mov01A
010.txt _0mov00A _1mov00A 2.txt 4.txt mov002 mov00A mov00aA mov010
$
I used ls -1
by itself or preceded by various LANG=
options and the order of files is as shown below:
ls -1 |
ls -1 LANG=en_GB.utf8 | ls -1 LANG=C
ls -1 LANG=en_US.utf8 | ls -1 LC_ALL=C
---------------------------------------
_010.txt | 01.txt
010.txt | 010.txt
01.txt | 1.txt
_0mov00A | 10.txt
10.txt | 2.txt
_1mov00A | 3.txt
1.txt | 4.txt
2.txt | _010.txt
3.txt | _0mov00A
4.txt | _1mov00A
mov001 | _mov00A
mov002 | mov001
mov00a | mov002
mov00A | mov00A
_mov00A | mov00B
mov00aA | mov00a
mov00B | mov00aA
mov010 | mov010
mov01A | mov01A
But when I use the Natural sorting
option (Dolphin Preferences > General > Sorting Mode) of Dolphin 17.12.3 which is the default version of Kubuntu 18.04, I get a different sorting order as shown in the Name
column in the image below:
My question: how does Dolphin achieve this type of sorting?
The Dolphin Handbook doesn't have much to say:
Sorting Mode controls how items are sorted in the view. If Natural
sorting is enabled, the sort order of three example files will beFile1,
File2,
File10.
If this option is disabled, the normal alphabetical sorting case
sensitive or case insensitive will be used, which leads to the sort
orderFile1,
File10,
File2.
Best Answer
"Natural sorting" detects numbers in file names and uses numerical sorting on this part of the filenames, therefore 010.txt and 10.txt come after 4.txt (10 > 4).
1 < 2 < 10, so mov001 and mov01A come before mov002 and mov010.
0 < 1 < 10, therefore _0mov00A < _1mov00A < _010.txt
etc.