How To: ls colorized output in MacOS

I’m pretty used to how ls command shows pretty colorized output on most modern Linux distros, but somehow its default behaviour in MacOS is still plain white – no different colours.

I decided to look for command line option to change that, and sure enough – ls command in MacOS has -G option for colorizing output.

So, instead of running this:

$ ls /etc

you’ll run this:

$ ls -G /etc

Check out the different it makes below!

Plain ls /etc in MacOS

2018-11-10_17-26-52.png

Colorized ls -G /etc in MacOS

2018-11-10_17-27-33.png

Make colorized alias for ls command

If you like this enough, I suggestt you make an alias for ls -G:

$ alias ls='ls -G'

what this does is you can run ls, but your bash shell will be recognizing it as alias name and running ls -G instead. Any additional command line options will work, of course:

2018-11-10_17-33-46.png

Add ls alias to .bash_profile

To make this permanent, add ls alias to your .bash_profile:

$ echo "alias ls='ls -G'" >> $HOME/.bash_profile

What this will do is any new Terminal windows you open on your Mac will have the ls command alias preconfigured, so you’ll always have the output colorized.

See Also