2

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

enter image description here

But in Geeqie, I see same as in BASH:

enter image description here

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?

  • Related: This old post had asked "Nautilus sorting by filename column seems insane" and one comment noted "Nautilus is known not to honour the system-wide environment variable..." – clearkimura Apr 2 '17 at 6:27
0

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 (the test file has your four example filenames), my approach would be to play around with that and define aliases like alias sort="LC_COLLATE=C sort"if necessary:

> sort test # my system standard is LC_COLLATE=de_DE.UTF-8
flop_drop.jpg
flop.jpg
flop_nop.jpg
flop_qrop.jpg
> LC_COLLATE=C sort test
flop.jpg
flop_drop.jpg
flop_nop.jpg
flop_qrop.jpg

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:

> find . -name "flop*" # my system standard is LC_COLLATE=de_DE.UTF-8
./flop.jpg
./flop_drop.jpg
./flop_qrop.jpg
./flop_nop.jpg
> LC_COLLATE=de_DE.UTF-8 find . -name "flop*"
./flop.jpg
./flop_drop.jpg
./flop_qrop.jpg
./flop_nop.jpg
> LC_COLLATE=en_EN.UTF-8 find . -name "flop*"
./flop.jpg
./flop_drop.jpg
./flop_qrop.jpg
./flop_nop.jpg

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.