6

On Linux,on GitHub, in bash on iTerm2, and generally by convention most everywhere else, the following files would have the following order:

_01_file
_03_file
_2_file

In Mac® Finder, however, they have this order:

_01_file
_2_file
_03_file

Can this behavior be changed? If so, how?

Likewise, is it possible to have directories appear at the top of a list of files in Finder, as is common in Nemo/Nautilus?

To be redundant:

$ ls
_01_file  _03_file  _2_file

and:

enter image description here

Re: Allan's comment:

enter image description here

is there an option somewhere else that can change ascii precedence?

12
  • 1
    I can't replicate this problem; the listing shows exactly like you'd expect it to in both Finder and in Terminal. I don't understand what you mean by "on github, iTerm2." How does an online service and a Terminal application impact how files are listed in a shell? iTerm doesn't reorder anything. Right click in your Finder window and go to Arrange By.." Let us know what you have selected.
    – Allan
    Commented Feb 10, 2020 at 18:37
  • Edited for clarity. They are sorted by name in Finder's GUI Commented Feb 10, 2020 at 18:48
  • Re: github: the ordering of the files follows what I see in the terminal. Finder follows a different convention. Commented Feb 10, 2020 at 18:50
  • 2
    Does this answer your question? How does finder sort folders when they contain digits and characters?
    – klanomath
    Commented Feb 10, 2020 at 19:05
  • 1
    I think we can have 3 to 5 dupliacates of this open for good coverage. Especially if the answer or questions can be linked with edits as opposed to only comments linking them. Also we can merge down so all the good answers end up on whichever question becomes canonical through a Ask Different Meta post.
    – bmike
    Commented Feb 10, 2020 at 21:58

1 Answer 1

9

Is there a way to change the order in which the finder alphabetizes?

Unfortunately, no.

Since Mac OS X 10.0 "Cheetah", when sorting items by filename in Finder, files are sorted using the Unicode Collation Algorithm, with an additional specification that numeric substrings are sorted by numeric value, i.e. if multiple files exist whose filenames are of the form xny, where x is a susbtring that does not end with a digit, n is a substring which only consists of digits, and y is a substring that does not begin with a digit, then each such n is treated as a numeric value rather than a sequence of bytes, and the files are sorted accordingly. There is no option to disable this "natural canonical sorting", as some refer to it. This is stated officially in Apple's File System Programming Guide for macOS (§ File System Details):

The Finder

Because the Finder is the user’s main access to the file system in macOS, it helps to understand a little about how the Finder presents and works with files.

Filename Sorting Rules

The Finder’s sort order for file and directory names is based on the Unicode Collation Algorithm (Technical Standard UTS #10) defined by the Unicode Consortium. That standard provides a complete and unambiguous sort ordering for all Unicode characters and is available on the Unicode Consortium website (http://www.unicode.org). The Finder alters the default sorting behavior of this algorithm slightly by taking advantage of some sanctioned alternatives, specifically:

  • Punctuation and symbols are significant for sorting.
  • Substrings of digits are sorted according to their numeric value, as opposed to sorting the actual characters in the number.
  • Case is not considered during sorting.

Note that this behaviour is only exhibited by Finder itself. Other programs, such as the plain old BSD ls that comes packaged with macOS, behave in their own ways; typically, such BSD utilities abide by the Unix-style convention of sorting "lexicographically", i.e. by character encoding value.

Is it possible to have directories appear at the top of a list of files in Finder?

This can be done using the "Arrange/Group by Kind" option, but this then applies to other categories of files as well (e.g. media, documents), not just folders. Note that this does not group them by file extension, but rather into a set of groups defined by Apple.

If you just want folders first, but don't want everything else put into those other groups, then you should set "Group by" to "None", "Sort by" to "Name", and enable the following Finder preference:

  1. Open Finder.
  2. Press +,; or go to [Finder] in the menu bar, then [Preferences...].
  3. Go to [Advanced] and Enable "Keep folder on top: in windows when sorting by name". (This setting has slightly different names in various versions of macOS, e.g. "Keep folders on top when sorting by name" in macOS Sierra.)

There is no way to sort/group the files by their file extension; setting "Sort by" to "Kind" sorts them according to the same groups that are used if you set "Group by" to "Kind", just without showing the group headings.


As a workaround to both of these issues, you can use an alternative file browser such as Path Finder, which was partially designed to cater to these specific use cases.

5
  • Do you have a reference that explains where one makes this choice in PathFinder? I assume it must exist but have never found one online (I don't have the app). Commented Feb 10, 2020 at 21:46
  • @TomGewecke I've only used Path Finder a handful of times in the past just out of interest, and I do recall it sorting this way, but it actually sadly seems that this behaviour has changed, and Path Finder 9 sorts by filename in precisely the same way as macOS Finder. I've opened a support query to try and get a definitive answer, as I can't find any references to sort order in their documentation.
    – Jivan Pal
    Commented Feb 10, 2020 at 22:50
  • @JivanPal, I think you'll find there IS a way to make the Finder sort folders first. Many years ago I applied this setting and when a Finder window is sorted by Name, the folders all appear first, themselves sorted by name, followed by files similarly sorted by name. Sorting on other criteria (e.g. dates) does not apply the 'folders first' rule. The trouble is, it is so long ago I set this, I have completely forgotten how I did it. A somewhat obscure terminal command I think. No doubt it could be discovered again.
    – UKenGB
    Commented Dec 5, 2022 at 9:51
  • @UKenGB Hmm, after some googling, I've found it: Finder > Preferences > Advanced > Keep folders on top > In windows when sorting by name. Thanks for this, very handy to me also. I'll edit my answer in a bit!
    – Jivan Pal
    Commented Dec 5, 2022 at 10:02
  • @JivanPal Well done. That's it, although I was convinced it was a terminal command. As I said, long time ago.
    – UKenGB
    Commented Dec 6, 2022 at 19:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .