4

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.

1 Answer 1

2

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 :)

4
  • Thanks for the answer. Do you think there would be a shortcoming of using gls instead of ls in any situation? Commented Feb 12, 2015 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. Commented Feb 12, 2015 at 22:52
  • 2
    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. Commented Feb 14, 2015 at 8:52
  • How do add color to folder name with this command? Commented Sep 5, 2018 at 14:18

You must log in to answer this question.

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