How do I get ls --color=auto to work on Mac OS X?

Solution 1:

ls is actually separate from Bash. Mac OS X has a BSD version of ls, which requires -G on the command line, or CLICOLOR (and perhaps LSCOLORS) in the environment.

See man ls for more info.

Solution 2:

Open the terminal window and type:

alias ls='ls -G'

Then hit Enter and done!

Solution 3:

Use Homebrew.

brew install coreutils

Note that this will throw a prefix of g in front of all the commands (e.g., gls for ls). It gives an option to source a file that will alias these for you automatically.

I wasn't sure if there was an option to install them directly without having to do the whole alias thing, so instead in installed MacPorts and did this.

Solution 4:

compatibility for GNU and *BSD/darwin ls

~/.profile

#for *BSD/darwin
export CLICOLOR=1

ls --color=auto &> /dev/null && alias ls='ls --color=auto' ||

~/.bashrc (I don't remember if bash on Linux always reads ~/.profile, but not my zsh on ARCH)

[[ -f $HOME/.profile ]] && source $HOME/.profile

Solution 5:

You'll need to install an alternate version of ls. The one usually used in linux is from the GNU coreutils project.

You could build and install or install from macports, fink or homebrew.