Sorting in finder giving unexpected results when using numbers and letters [duplicate]

I think this is alphabetical vs natural search order being used in Terminal(or wherever the code block comes from) and Finder respectively.

Why is a folder which starts with a 2 on the bottom?

Because it is 27 which is treated as a block while sorting and is greater than other single numbers which are also being treated as blocks. Another example is in the longer screenshot. 5f comes before 06a as 5 is smaller than 06.

Numbers are smaller than alphabets in both cases.

In the code block, we have character-wise sorting where single digits are being compared. So a larger number like 062 sometimes comes before 06a as 2 is smaller than a.

For example, in alphabetical sorting "z11" would be sorted before "z2" because "1" is sorted as smaller than "2", while in natural sorting "z2" is sorted before "z11" because "2" is sorted as smaller than "11".

Alphabetical sorting:

z11

z2

Natural sorting:

z2

z11

Functionality to sort by natural sort order is built into many programming languages and libraries

https://en.wikipedia.org/wiki/Natural_sort_order

Mac OS X sorting is based on the Unicode Collation Algorithm (Technical Standard UTS #10) defined by the Unicode Consortium. This standard provides a complete and unambiguous sort ordering for all Unicode characters and is available on the Unicode Consortium website (http://www.unicode.org).

There are no hints that this behaviour can be changed in Finder. It was observed in 2002-03:

  • http://hints.macworld.com/article.php?story=20021002061850171

  • https://apple.stackexchange.com/a/375244/313842 Comments under here suggest using apps like Pathfinder.

  • https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFileSystem/Articles/SortingRules.html#//apple_ref/doc/uid/20002377-BCIJIGDE

  • https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemDetails/FileSystemDetails.html