Is it possible to make the default of Terminal such that when I use the ls command it lists the directories first and then the files?

I figured out that this can be done by using coreutils and the command gls --group-directories-first, but I was wondering if there was an OS X native way to do this without coreutils.


The short answer is no. The ls shipped with OSX is not the GNU ls therefore it doesn't have the same options.

But you can get a similar result with :

ls -al | sort -k1 -r

Ps: I agree that it's far from perfect :)

| improve this answer | |
  • Thanks for the answer. Do you think there would be a shortcoming of using gls instead of ls in any situation? – sodiumnitrate Feb 12 '15 at 22:29
  • 1
    I'm using gls (with an alias on ls) for 2 or 3 years right now. It never has been problem. – Matthieu Riegler Feb 12 '15 at 22:52
  • 1
    AFAIK, gls will miss some extended file attributes as the builtin ls. For example, '/bin/ls -d ~/Dropbox' reports drwx------@ while 'gls -d ~/Dropbox' reports drwx------ for the permission field. – Hongxu Chen Feb 14 '15 at 8:52
  • How do add color to folder name with this command? – Adriano Resende Sep 5 '18 at 14:18

You must log in to answer this question.

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