Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1614  / 3 Years ago, mon, july 5, 2021, 5:49:46

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:



Natural Sorting in Dolphin



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 be



File1,



File2,



File10.



If this option is disabled, the normal alphabetical sorting case
sensitive or case insensitive will be used, which leads to the sort
order



File1,



File10,



File2.



More From » kubuntu

 Answers
6

Sorting for Humans : Natural Sort Order, discusses the usefulness of natural sorting but doesn't deal with how filenames with a leading _ are listed before other files.



The answers to How do I make ls sort underscore characters first? address the leading _ issue.



A solution using shell expansion to bypass any sorting by ls has:



ls -lf _* [!_]*


So, for the files in the question,



ls -lf -1 _* [!_]*


provides the same sort result as does Dolphin's natural sort:



$ ls -lf -1 _* [!_]*
_010.txt
_0mov00A
_1mov00A
_mov00A
010.txt
01.txt
10.txt
1.txt
2.txt
3.txt
4.txt
mov001
mov002
mov00a
mov00A
mov00aA
mov00B
mov010
mov01A
$


I don't know if this is the exact same mechanism that Dolphin incorporates to provide natural sorting.


[#8081] Monday, July 5, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
impisaso

Total Points: 423
Total Questions: 106
Total Answers: 104

Location: Virgin Islands (U.S.)
Member since Tue, Feb 2, 2021
3 Years ago
;