ls sorts filenames strictly lexicographically, comparing character by character, so e.g. "055436307" is compared as the characters "0", "5", "5", etc. so it sorts before "121134" because "0" is less than "1". if all compared characters match and one string ends, the shorter one comes first. Symbols like _ are just more characters, and their position relative to digits depends on the locale’s collation table. Google D…
It feels like this algorithm could be improved though. If a number has leading zeros you probably don't want to sort it numerically. That said the author's situation where it's numerical and different lengths seems likely rare enough that it probably isn't worth complicating things.
When I say “alphabetical order”, I mean “alphabetical order”
211–220 of 385 posts
Re: When I say “alphabetical order”, I mean “alphabetical order”
#212Earlier quoted context omitted.
The sort rules are simple (1). Treat any consecutive sequence of digits as a number when sorting. So for example version numbers (which must be massively more common than decimals in filenames) work correctly, and 5.9 is indeed smaller than 5.10 and the latter is not identical to 5.1 . Given that this idea goes back more than two decades, has been the default behaviour of the most used OSes for many years, with no ma…
> The sort rules are simple In considering the simplicity of the rule, I think you're using a developers perspective here where we automatically classify numbers and have a clear mental model of the separation between value and representation. But I'm not sure how simple it would be to explain to a non-technical user why size_5, size_10 and size_15 are in order but size_0.25, size_0.5 and size_0.75 are out-of-order.…
Because EVERYTHING a computer does to non-developer/technical users is "strange and confusing". With few exceptions, most people have no idea why their computer does something the way it does, or how they could make it do something different even if they wanted it to. And most of the time, when they complain about it to someone knowledgeable the answer will be some variant on "that's just sort of the way it is". Imagine a world where the names are sorting the way that the OP is looking for, you're still having to explain to someone why the first group sorts "out of order" and the second group sorts "in order". And if they complained, they would almost certainly get an answer that is some variant on "that's just sort of the way it is".
Re: When I say “alphabetical order”, I mean “alphabetical order”
#213Earlier quoted context omitted.
> The sort rules are simple In considering the simplicity of the rule, I think you're using a developers perspective here where we automatically classify numbers and have a clear mental model of the separation between value and representation. But I'm not sure how simple it would be to explain to a non-technical user why size_5, size_10 and size_15 are in order but size_0.25, size_0.5 and size_0.75 are out-of-order.…
> I'm regularly amazed at how little non-developer/technical users complain about strange and confusing behavior. I am a highly technical user that works with a lot of people with traditional engineering degrees but little to no software experience (except as frequent users). The answer here is that they've learned that all computer software is arcane and mysterious, and so they just accept that there will be strange…
> traditional engineering degrees
What does that mean? What disciplines? I cannot believe that all junior graduates in engineering disciplines in the 2020s are not doing some programming, even if just writing macros in a CAD program.Re: When I say “alphabetical order”, I mean “alphabetical order”
#214I agree with Microsoft/Google/KDE's order. The author's situation is extremely rare, and the situation where someone wants "10" to be before "9" is far more common. Moreover, desktops don't label this sorting "alphabetical" (E: and it would really be "lexicographic"*), they label it "by name" (an informal criteria), so technically they're not lying. > I miss the time when computers did what you told them to, instead…
Re: When I say “alphabetical order”, I mean “alphabetical order”
#215I agree with Microsoft/Google/KDE's order. The author's situation is extremely rare, and the situation where someone wants "10" to be before "9" is far more common. Moreover, desktops don't label this sorting "alphabetical" (E: and it would really be "lexicographic"*), they label it "by name" (an informal criteria), so technically they're not lying. > I miss the time when computers did what you told them to, instead…
Re: When I say “alphabetical order”, I mean “alphabetical order”
#216I agree with Microsoft/Google/KDE's order. The author's situation is extremely rare, and the situation where someone wants "10" to be before "9" is far more common. Moreover, desktops don't label this sorting "alphabetical" (E: and it would really be "lexicographic"*), they label it "by name" (an informal criteria), so technically they're not lying. > I miss the time when computers did what you told them to, instead…
I'm not sure I agree. I think I could be convinced if there was a unique and universal representation for numeric values using characters. But we have so many textual representations of numeric values that I'm assuming the "mind-reading" goodness only works for a small subset. And the subset will be somewhat intuitive for developers but unlikely to be so for non-technical people. For example, does the order handle nu…
Worse, if the answer is yes to any of these questions, it's also likely to lead to surprise/confusion. The only way to win is not to play.
Re: When I say “alphabetical order”, I mean “alphabetical order”
#217I agree with Microsoft/Google/KDE's order. The author's situation is extremely rare, and the situation where someone wants "10" to be before "9" is far more common. Moreover, desktops don't label this sorting "alphabetical" (E: and it would really be "lexicographic"*), they label it "by name" (an informal criteria), so technically they're not lying. > I miss the time when computers did what you told them to, instead…
Re: When I say “alphabetical order”, I mean “alphabetical order”
#218I agree with Microsoft/Google/KDE's order. The author's situation is extremely rare, and the situation where someone wants "10" to be before "9" is far more common. Moreover, desktops don't label this sorting "alphabetical" (E: and it would really be "lexicographic"*), they label it "by name" (an informal criteria), so technically they're not lying. > I miss the time when computers did what you told them to, instead…
I'm not sure I agree. I think I could be convinced if there was a unique and universal representation for numeric values using characters. But we have so many textual representations of numeric values that I'm assuming the "mind-reading" goodness only works for a small subset. And the subset will be somewhat intuitive for developers but unlikely to be so for non-technical people. For example, does the order handle nu…
The specific option for numeric sorting is “kn”.
As far as I can tell, every operating system and many other interfaces tend to use this standard algorithm.
https://www.unicode.org/reports/tr35/tr35-collation.html#CLD...
Re: When I say “alphabetical order”, I mean “alphabetical order”
#219The so-called "natural" sort makes sense for version numbers and enumeration (without zero-padding) but I'm more often dealing with file names with a datetime (like in the article), a hexadecimal hash, or just randomized string of characters that includes numbers. In those cases "natural" sort makes it harder to find the file you're looking for. Even when files are enumerated it's pretty rare to have more than 9 part…
I agree with you on this point.
> a datetime
AFAICT, natural sort shouldn't ever make datetimes harder to find, unless they are formatted inconsistently, as in the author's case. Suppose one camera wrote dates as 20250928 and another as 2025-09-28. ASCIIbetical sort would do nothing to help here.
Natural sort can even improve things over ASCII sort, for instance if someone is stuck with a format like "28/9/2025" or "September 2 2025"
Re: When I say “alphabetical order”, I mean “alphabetical order”
#220Earlier quoted context omitted.
> I'm regularly amazed at how little non-developer/technical users complain about strange and confusing behavior. I am a highly technical user that works with a lot of people with traditional engineering degrees but little to no software experience (except as frequent users). The answer here is that they've learned that all computer software is arcane and mysterious, and so they just accept that there will be strange…
> traditional engineering degrees What does that mean? What disciplines? I cannot believe that all junior graduates in engineering disciplines in the 2020s are not doing some programming, even if just writing macros in a CAD program.