Sample Header Ad - 728x90

How to get "ls" and "sort" commands to reproduce Finder.app sorting using LC_COLLATE

1 vote
1 answer
147 views
In Apple Finder.app special characters come before numerals which then are followed by alpha characters. It appears this is called "Natural Sort Order". **EDIT** To clarify, I am using ls because I am trying to copy file names from Finder to a text document and have them sorted as Finder sorts . To test I created 7 files with the names below using touch {[,1,2,3,A,B,C,}
[
1
2
3
A
B
C
Using ls -f the bracket ends up after numerals and before alpha characters instead of at the beginning. 0-zsh% ls 1 2 3 A B C [ 0-zsh% ls -f . .. 1 A C 3 [ B 2 I have tried changing the locale in the shell without luck. This is my locale:
0-zsh% locale                                  
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL="C"
These are possible english locale options
0-zsh% locale -a | grep -i en
en_NZ
en_US.US-ASCII
en_US.UTF-8
en_NZ.ISO8859-1
en_AU.US-ASCII
en_US
en_NZ.UTF-8
en_AU.ISO8859-15
en_US.ISO8859-15
en_NZ.ISO8859-15
en_AU.UTF-8
en_CA
en_NZ.US-ASCII
en_GB.ISO8859-1
en_CA.US-ASCII
en_CA.ISO8859-15
en_US.ISO8859-1
en_GB.UTF-8
en_GB.US-ASCII
en_AU
en_GB
en_CA.UTF-8
en_IE.UTF-8
en_CA.ISO8859-1
en_AU.ISO8859-1
en_IE
en_GB.ISO8859-15
https://www.engadget.com/2008-06-24-mac-101-finder-filename-sorting.html
Asked by John (1248 rep)
Oct 17, 2022, 11:40 PM
Last activity: Oct 19, 2022, 02:22 PM