Color Your OS X Command Prompt

In the comments of Customize Prompt On Mac OS X, jh asks how to color your command prompt:

How about the colored bits below the command prompt?
I’ve noticed that when I do an ‘ls’ on my own mac it tends to be monochromatic, however, when I’m ssh-d in to a linux machine and ‘ls’ I tend to get output that colors directories, and executables differently.
Why is this? And is there any way to get my own mac’s output to be color coded as well?

Of course there is!

Open up ~/.bash_profile and add the following two lines:

export CLICOLOR=1
 export LSCOLORS=ExFxCxDxBxegedabagacad

Save, exit, log out, log in, and there you are!

Terminal-Coloring

Update: For tcsh users, I was able to get the same effect putting the following in ~/.tcshrc:

setenv CLICOLOR "1"
 setenv LSCOLORS "ExFxCxDxBxegedabagacad"

For iTerm users, add the following to ~/.bash_profile:

export TERM=xterm-color
 alias ls='ls -G'
 alias ll='ls -hl'


 
 

29 Responses to “Color Your OS X Command Prompt”

  1. 4Avatars
    Steve
    If you are using a substitute Terminal like iTerm, you need to set the TERM variable to one that is capable of displaying color with: export TERM=xterm-color

  2. Hrmm... strange.
    I'm running 10.3.8, and made the file as you wrote. I then logged out, logged back in, ran bash (normally use tcsh), did ls and no pretty colours! Any idea what I'm doing wrong?

  3. Mark,

    Make sure your TERM is set to xtern-color like Steve suggested above.

    Also, run the commands from .bash_profile from the command prompt and see if coloring works. It may be a problem with your Mac not running the login script.

    - Brad

  4. Brad, I just ran the commands and they worked. It must be the Mac is not running the login script - how would I fix that; any ideaS?

  5. Hey Mark,

    OK, try placing it in ~/.bashrc and see if that works.

    Oh, and incase you were wondering about the difference between .bash_profile and .bashrc

    ~/.bash_profile is executed when you login
    ~.bashrc is executed when the shell starts


  6. 4Avatars
    Darren
    I have never been able to get iTerm to work properly. No matter what I do if prefs or even config windows it just does plain window. I even tried ALL of the above and no luck.

    Just switched back to good old Terminal and it worked great, colours everywhere! ;)

  7. 4Avatars
    Mitch
    Is there an equivalent command for tcsh that I can put in .tcshrc? Or, is this a bash only thing. Thanks for your help in advance.

  8. Mitch,

    I was able to get this working with tcsh by putting the following in .tcshrc

    setenv CLICOLOR "1"
    setenv LSCOLORS "ExFxCxDxBxegedabagacad"

    - Brad

  9. Darren,

    I was able to get colors working in iTerm by putting the following in ~/.bash_profile:

    export TERM=xterm-color
    alias ls='ls -G'
    alias ll='ls -hl'

    - Brad

  10. How do you adjust the colors?

    - Ian


  11. Easier way to do this, in Terminal preferences, set your terminal to one that can display colour. Then add "alias ls 'ls --color=yes'" to your .cshrc file. As I don't use bash, I don't know if it would be the same there.

  12. Thanks for an alternate way of doing this Hasan.

  13. 4Avatars
    Mitch
    Brad,
    Thanks, your suggetion to put
    setenv CLICOLOR “1″
    setenv LSCOLORS “ExFxCxDxBxegedabagacad”
    in .tcshrc worked great.
    Mitch


  14. Trackback
    blog.syslinx.org

    mactips.org

    mactips.org is a nice blog with some really interesting tips and hints concerning all OS X topics. It’s now added to NetNewsWire. :)

    Okay, I could have figured it out myself, but with the help of mactips.org, I finally made /bin/ls produce colored …



  15. Trackback
    Surf 11

    Colorize your Mac Terminal



  16. Trackback
    Kalixia » Blog Archive » Adding support for colors in Mac terminal

    [...] I was a bit disappointed at the poor support of the Terminal and iTerm for colors on a Mac system. I googled and found an article explaining how to colorize the OSX prompt. [...]


  17. 4Avatars
    Kostas
    Thanks a lot! I was trying to figure out how to do this for very long!

  18. 4Avatars
    DrS
    Is there any simple way to have every new X11 terminal window automatically assume a different colour? Can't seem to find this on google


  19. Trackback


  20. Trackback
    Diogo Gomes Blog : bash in living color

    [...] trick is explained in here, and mostly consists [...]


  21. 4Avatars
    pqs
    I'm using bash and this didn't work.

    At the end it worked when I added this alias to .bashrc

    alias ls='ls --color=always'


  22. Trackback
    Color Your Command Prompt Ver.2.0 - MacTips: OS X Tips & Tricks

    [...] was a previous post made on coloring your terminal. It kind of interested me but I didn’t like colors or the [...]



  23. Trackback
    Color Your Command Prompt 2.0 - MacTips: OS X Tips & Tricks

    [...] was a previous post made on coloring your terminal. It kind of interested me but I didn’t like colors or the [...]


  24. Worked Great for years I wanted color back in my terminal.
    Always used linux and had to do something similar to get color working with slackware


  25. Trackback
    Aggiungere una directory alla path di sistema di Leopard « doc.Jek

    [...] ottenere questo risultato è sufficiente seguire una delle tante guide che potete trovare in rete (qui una). L’aspetto interessante sta nel fatto che le modifiche possono essere effettuate (per [...]


  26. Thanks for the information Brad!

  27. 4Avatars
    Pkhunter
    Coloring terminal is no big deal. But how can we change the hideous colors that show up even with "ls -g"? It shows up in a lousy blue. Can I change that?

Post a comment to "Color Your OS X Command Prompt"