Add Color to the Terminal in Mac OS X

Feb 21, 2012 - 14 Comments

Color Terminal

Adding colorized ls output to the Terminal in Mac OS X is a good way to make navigating around the command line a bit easier on the eyes. This makes different items show up in different colors, including directories, files, executables, and symbolic links.

We’ll cover a customizable color output setting for both dark and light terminals, and you can get a preview of color ls output by typing “ls -G” at the command line. The preview with ls -G will depend on the Terminals color settings and won’t necessarily represent the colors shown in the screenshots below, however.

  • Open Terminal and type: nano .bash_profile

  • Use the arrow keys to navigate to the bottom of the document and paste in either of the blocks of text below, depending on the terminals appearance (see man entry below for further customizations)

Colors for Dark Terminal Themes:
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

Dark Terminal Colors

Colors for Light Terminal Themes:
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad

Light Terminal color theme

  • After the strings are pasted into .bash_profile confirm that it looks something like this in nano:
  • Color Terminal string in bash profile

  • Hit Control+O to save and open a new Terminal window
  • Type “ls” or “ls -la” to confirm the colorized output

Optionally, you may want to create an alias in .bash_profile to link ls to something like ls -GFh, this would look like:

alias ls='ls -GFh'

This will work with Mac OS X 10.6, OS X 10.7, OS X 10.8, and beyond, as long as you are using the bash shell. If you aren’t certain what shell you are using, look in the Terminal window titlebar for “bash”, or you can check with the following command:

echo $SHELL

The output will be “/bin/bash” if it’s bash, and something else if not.

Don’t forget that you can also change the appearance of Terminal windows instantly and change the Terminal wallpaper too.


Customizing LSCOLORS Manually
If the above color choices weren’t doing it for you, you can set whatever you want. Here’s the manual page on LSCOLORS if you want to give it a shot. The default is “exfxcxdxbxegedabagacad” but clearing out the .bash_profile color entry will remove any hideous color combinations too.

LSCOLORS The value of this variable describes what color to use
for which attribute when colors are enabled with
CLICOLOR. This string is a concatenation of pairs of the
format fb, where f is the foreground color and b is the
background color.

The color designators are as follows:

a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background

Note that the above are standard ANSI colors. The actual
display may differ depending on the color capabilities of
the terminal in use.

The order of the attributes are as follows:

1. directory
2. symbolic link
3. socket
4. pipe
5. executable
6. block special
7. character special
8. executable with setuid bit set
9. executable with setgid bit set
10. directory writable to others, with sticky bit
11. directory writable to others, without sticky
bit

The default is “exfxcxdxbxegedabagacad”, i.e. blue fore-
ground and default background for regular directories,
black foreground and red background for setuid executa-
bles, etc.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line, Customize, Mac OS X, Tips & Tricks

14 Comments

» Comments RSS Feed

  1. James says:

    Terminal looks so boring in this day and age, whatever happened to TermKit? It hasn’t been updated since it first was released, so much hope and it went no where.

  2. Mrs.Hopper says:

    Wow! Love this tip. Thank you very much

  3. vdiv says:

    Excellent tip! What if one uses xterm under X11?

  4. James says:

    Add the IR_Black theme to Terminal here – http://blog.toddwerth.com/entries/13

    IR_Black comes from a Textmate theme and uses more pastel colors that just are more visible on a dark black background.

    Then just make it the default settings. The only change I would make is a choice of a better fixed width font and change the highlight color to something brighter.

  5. Ron says:

    When I use Control+O to sad it asks what name to save it as. Can I use any name, since it will not let me save it as the existing name?

  6. […] recently covered the classic method of adding colors to the command line by editing .bash_profile, but it turns out that Terminal in OS X Lion and OS X […]

  7. John says:

    I try to save .bash_profile using Control+O command, but it’s doesn’t work..

  8. Jefferson Borges says:

    Hi!
    Really nice post.. thanks a lot!
    I’ve been looking for this for like thousands..

    A question: Is there a way to make these parameters be valid when you open an SSH session?
    I ask it because when I open an SSH connection, it gets back to the default colorless version.

    Thanks!

  9. […] run ls, and see the difference. Still not satisfied with the appearance, or have you already done that? There’s more to […]

  10. Mike says:

    Thanks for your tip. Great for ls.

    I copied colordiff to /usr/bin and put ‘alias diff=colordiff’ in my .bash_profile. (colordiff is a pyhton script that performs a colourised diff).

    I also use:

    alias grep=’grep –color=auto’
    alias fgrep=’fgrep –color=auto’
    alias egrep=’egrep –color=auto’

    Which seem to work.

  11. Mike says:

    I forgot to say that you can colourise grep (and fgrep and egrep) without resorting to aliases. The following will suffice in a .bash_profile or such like:

    export GREP_OPTIONS=’–color=auto’
    export GREP_COLOR=’1;35;40′

  12. Ramesh says:

    My screen looked so boring and was difficult on eye difficult to differentiate file from directory. Now its all easy to see.Thank you very much.

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates