Tag Archives: color

Adding some color to ls in Mac OS

If you have ever used ls in the Mac OS terminal you have probably noticed that you get a boring monochrome list. If you have never used Linux before you might not find this a problem at all. Why would you anyone expect or need it to have color? Well, sometimes color is very important, for instance if you are in an unfamiliar directory and you don’t know what is a file and what is a sub-directory.If you are completely new to the Terminal/Unix-like operating systems a short explanation of what ls is is in is a program which lists all of the files and directories in a directory. Try opening the terminal and typing ls to see what I mean (type man ls for more information on how to use ls). On a mac, and all other BSDs to my knowledge, the output text will all be in one color (probably black in your case),but on Linux the output will be color coded (files and directories have different color text)So you want Mac OS to have colored output just like Linux? well, that is easy. ls has the argument -G which will output colored text (on Mac OS. Linux uses -C (–color) but you shouldn’t need that, and I don’t know what other BSDs do.) So, you could type ls -G every time you want to list the contents of a directory, but that would get every annoying after a while. There is an easy way you can make it output colors every time you run ls so you won’t have to add the -G every time! Go the command line and type:

cd ~/ (if you are not already there)

echo alias ls=’/bin/ls -G’ >> .bash_profile

Now every time you type ls you will see colored output (if you ever want to remove this just edit ~/.bash_profile with your favorite text editor and remove the line we just added) Enjoy!

Leave a comment

Posted by on December 21, 2008 in apple, bash, concatenation


Tags: , , , , , , , ,