How can I force File/Open dialogs and file managers to show files in lexical (not numerical) order?

I’m running Manjaro Mate, and every time I open a file manager (eg, Thunar or Caja) or a File/Open dialog (say, “change background picture” or File/Open in Sublime Text), files in directories are displayed in numerical order. How can I change that to lexical order (same as ASCII order except case-insensitive)??

Eg, instead of THIS:

1c2df351.jpg
001c8ce6.jpg
1c8631fd.jpg

how can I force the order to be this:

001c8ce6.jpg
1c2df351.jpg
1c8631fd.jpg

?

When you open such file browser - you are usually presented with the Recent set of files - those cannot be sorted.

Install the dconf-editor package - launch it and navigate to / org / gtk / settings / adjust the setting to your liking.

Ok. In Dconf Editor, “org.gtk.Settings.FileChooser” does have a setting called “sort-order”; however, the only two legal options are “ascending” and “descending”. Whereas, what I need is “lexical” instead of “numerical”.

The only other two sort-related items are “sort-column” (what to sort), and “sort directories first”.

I’m not seeing anything pertaining to methods of sorting (say, case-insensitive as opposed to case-sensitive, or lexical as opposed to numerical). Is it not possible to change sort method in Linux?

When not in the Recent window - click the column headers to change sort.

But I see your dilemma :slight_smile: - I have no idea - I reckon you have hit an edge case no one thought of before.

I have been playing around with your example filenames.

In a virtual terminal the files are listed as you expect

$ ls -l
-rw-r--r-- 1 fh fh 7758 19 apr 12:13 001c8ce6.txt
-rw-r--r-- 1 fh fh 1128 19 apr 12:12 1c2df351.txt
-rw-r--r-- 1 fh fh 2477 19 apr 12:13 1c8631fd.txt

However in a filemanager the listing is the one you sampled - so I think this is the file manager interpreting the filenames.

The file manager uses the filebrowser module provided for the toolkit on which the application is built.

On my system (kwin/plasma) Sublime Text seems to be utililzing GTK - the same for Firefox while Qt Designer has a clearly distinctive look - the same has Kate.

So - and I am only speculating - I have otherwise no knowledge of how the filechooser work - it seems the filebrowser modules of the respective toolkits is implementing a strange name sorting logic.

The only pattern I can see is the numbers before letters pattern where a zero before number means nothing - throw away which gives

1c2df351
1c8ce6
1c8631fd

I took it a step further - adding a letter as the first char to break any number translation - but same result.

m1c2df351
m001c8ce6
m1c8631fd

To me it just adds to the confusion of what sorting algorithm is implemented - there must be a logic somewhere - it just eludes me.

Playing with notation

hex dec
1c2df351 472773457
001c8ce6 1871078
1c8631fd 478556669
1 Like

Interesting about this issue likely being “toolkit” dependent. I suppose it makes sense for file managers to farm-out sorting to a “sort” module.

But I can’t agree that this is an “edge case”. It’s hardly the case that computer scientists have only discovered “hexadecimal numbers” in 2022. (Maybe… 1622? I’m pretty sure they’ve been around for hundreds of years.) And people have been using hexadecimal numbers as file names for decades. So I have to think that this issue has come up lots in Linux as it has in Windows. (Windows has the same bug, but in their case, one can do a registry hack that fixes it.)

I do note that if I call ls from bash, it doesn’t have the bug. For example, these file names are sorted correctly by ls:

00bad131e2f706e32829cb42eba5f77e5b3b6d24.jpg
04a43c4f2e134b6f5ab35ee99ebfeebf66f3618a.jpg
06c39800b0e0f9f5b0aa9d6df14d7cb0f43b8db0.jpg
09b550c149b0b1485c22f3b845d9d0505de33575.jpg
0a2327cb1f385fa382e218c7843ec38484c2825c.jpg
1b938893eecd0a02f065e06a64a767ca8688da3c.jpg
1f8ca67e8361cc47eeafe65f2d1cd847ed782cd9.jpg
4ac1fee4456bbb098ff22baa5ffa7ec3f8bfb6c2.jpg
8feed6f47f579dee0c565ef9e5113e4f6a78d889.jpg

But in Caja, Thunar, and Dolphin, the order is this:

0a2327cb1f385fa382e218c7843ec38484c2825c.jpg
00bad131e2f706e32829cb42eba5f77e5b3b6d24.jpg
1b938893eecd0a02f065e06a64a767ca8688da3c.jpg
1f8ca67e8361cc47eeafe65f2d1cd847ed782cd9.jpg
04a43c4f2e134b6f5ab35ee99ebfeebf66f3618a.jpg
4ac1fee4456bbb098ff22baa5ffa7ec3f8bfb6c2.jpg
06c39800b0e0f9f5b0aa9d6df14d7cb0f43b8db0.jpg
8feed6f47f579dee0c565ef9e5113e4f6a78d889.jpg
09b550c149b0b1485c22f3b845d9d0505de33575.jpg

Which makes no sense whatsoever. Apparently Caja, Thunar, and Dolphin are using a “sort” module which is trying to do a “decimal numeric sort”, instead of a “case-insensitive lexical sort” as it should. Probably because, as you say, they were built from the same “tool kit” so use the same broken sorting routine. And I can’t find a setting for it.

I suppose I could try to find a file manager made from a “tool kit” other than “GTK”. Perhaps QT? Know of any file managers based on that?

Addendum: It turns out that Dolphin (which I installed about 5 minutes before my previous reply) has a GUI setting for “sorting mode”, which has 3 options:

  1. Natural [eg, unnatural]
  2. Alphabetical, case-insensitive [ YES!!! ]
  3. Alphabetical, case-sensitive [eh; might be useful for some things]

And I like the look and functionality of Dolphin. So that solves part of the problem. (But not file orders in file-open and file-save dialogs in apps; those are still broken.)