This is not a problem, but I'm just curious.
Why does the alphabetical listing of files differ among programs?
It appears to me as though each program implements its own approach for alphabetical sorting of file names. Maybe these flow from the libraries upon which programs draw. Clearly, they have different customs for the treatment of symbols like "_" or "-". I think it is a little odd that these are not consistent.
Here's an example. I create 2 files, "flop.png" and "flop_drop.png". In a BASH shell, the listing has:
-rw-rw-r-- 1 pauljohn pauljohn 3547 Apr 1 21:50 flop_drop.jpg
-rw-rw-r-- 1 pauljohn pauljohn 3547 Apr 1 21:50 flop.jpg
However, in Nautilus, that is reversed
But in Geeqie, I see same as in BASH:
While the UNIX find program agrees with Nautilus:
$ find . -name "flo*"
./flop.jpg
./flop_drop.jpg
I've seen various wrinkles like this, I don't entirely understand the pattern. I proliferate variations and the ls output in BASH indicates that it is including the suffixes in alphabetical sorting:
-rw-rw-r-- 1 pauljohn pauljohn 3547 Apr 1 21:50 flop_drop.jpg
-rw-rw-r-- 1 pauljohn pauljohn 3547 Apr 1 21:50 flop.jpg
-rw-rw-r-- 1 pauljohn pauljohn 3547 Apr 1 22:14 flop_nop.jpg
-rw-rw-r-- 1 pauljohn pauljohn 3547 Apr 1 22:15 flop_qrop.jpg
But Nautilus always leaves "flop.jpg" first, no matter what follows the underscore. I see Thunar does the same.
However, I installed an image viewer named "gwenview" for comparison. In there, we get something entirely different. The ordering is
flop_drop.jpg
flop_nop.jpg
flop_qrop.jpg
flop.jpg
Are there different schools of thought on how it ought to be done, or are these just accidental differences?
Apparently they use different locales for the LC_COLLATE environment variable, which defines “[h]ow strings (file names...) are alphabetically sorted” (source). You can display available locales for your system with
locale -a
. The following example shows how you can change the setting for one command only (thetest
file has your four example filenames), my approach would be to play around with that and define aliases likealias sort="LC_COLLATE=C sort"
if necessary:This answer to a related question gives a good overview on the locales, where they are defined and how you can change them.
Nautilus however apparently has a bug…
Edit
find
seems to ignore a manual setting of LC_COLLATE:I have absolutely no idea why it does behave that way, particularly because its manpage lists LC_COLLATE as used by the program. I'm left speechless here.