How can I list directories first in the terminal with zsh / ls command in Mac OSX?

Most of the similar questions / answers here don't work in Mac/OSX because there is not such a thing as --options.

I am using the ZSH shell, I've been trying commands said here: http://www.rayninfo.co.uk/tips/zshtips.html but without success.

Thanks for any help.


Instead of hacking around and parsing ls output—which is never a good idea—you could simply install the GNU Coreutils, which give you the GNU versions of ls, date, echo, head and tail, and many more, which offer much more than the BSD counterparts.

The easiest way to do that would be to install Homebrew, and then run brew install coreutils. Now, the GNU coreutils will be available prefixed with a g, and you could run:

gls -l --group-directories-first

Or, you could even alias that in your .zshrc:

alias ls='gls --group-directories-first'