7 Replies Latest reply: Jan 26, 2007 3:09 PM by Ken Nellis
Novadan Level 1 Level 1
Hi I was just wondering if someone could help me in determining what I need to add into my .bash_profile in order to enable colour in the xterm, ie so that when ls is used it color codes the different file types and directories as most unix terminals would do. As well if it is not a .bash_profile file that I need to edit my bash environment what file is needed?

MacBook Pro, Mac OS X (10.4.8), 1.83 GHz Intel Core duo
Solved by Jun T. on Jan 24, 2007 6:22 PM Solved
Hi Novadan,

In order to get color output from ls command, you need to set CLICOLOR

export CLICOLOR=

CLICOLOR can be set to any value (including null string, as above). You may put this line to your .bashrc.

If you still don't get color output, then you must also set TERM to xterm-color (may other color-capable terminals may also work). You can do this by adding

export TERM=xterm-color

to .bashrc. Another method is to add the following line to your ~/.Xdefaults

XTerm*termName: xterm-color

PowerMacG4, PowerBookG4, iMac(C2D)   Mac OS X (10.4.8)  
Reply by Zerwas on Jan 24, 2007 12:01 PM Helpful
Normally the .bashrc. If is not exit, create one with vi .bashrc.
In this file write all your Environment Variables.

All replies

  • Zerwas Level 4 Level 4
    Normally the .bashrc. If is not exit, create one with vi .bashrc.
    In this file write all your Environment Variables.
  • Jun T. Level 4 Level 4
    Hi Novadan,

    In order to get color output from ls command, you need to set CLICOLOR

    export CLICOLOR=

    CLICOLOR can be set to any value (including null string, as above). You may put this line to your .bashrc.

    If you still don't get color output, then you must also set TERM to xterm-color (may other color-capable terminals may also work). You can do this by adding

    export TERM=xterm-color

    to .bashrc. Another method is to add the following line to your ~/.Xdefaults

    XTerm*termName: xterm-color

    PowerMacG4, PowerBookG4, iMac(C2D)   Mac OS X (10.4.8)  
  • Ken Nellis Level 2 Level 2
    expertise.macosx
    Mac OS X
    Thanx for this info. I was aware that Darwin's "ls" doesn't colorize the same way as Linux versions do, but didn't know they could do it at all.

    BTW, it's more typical to put your export statements in your .bash_profile file so that they aren't redundantly executed for each new shell level.

    Finally, for more information, see the ls man page: % man ls

    iMac G4   Mac OS X (10.4.8)  
  • Novadan Level 1 Level 1
    This indeed does enable the color in the terminal, however is there a ways to get it to show the typical unix colors for the various types, i.e. directories, source code, executables, etc? Currently I only get some excutable and directories that are color coded.
  • Ken Nellis Level 2 Level 2
    expertise.macosx
    Mac OS X
    As I referenced, look at the "ls" man page, particulary the description of the LSCOLORS environment variable. At the terminal prompt, type: man ls
  • Jun T. Level 4 Level 4
    it's more typical to put your export statements in your .bash_profile


    Yes, it may be more "typical". But on MacOSX, by default, Apple's X11 invokes xterm without the -ls option, so the shell running in the xterm window is not a login shell. As you know, a login bash reads only .bash_profile while non-login bash reads only .bashrc. So CLICOLOR must be set in .bashrc (unless you configure your X11 so that xtem starts a login shell, by editing .xinitrc or .Xdefaults).

    In theory, .bash_profile is for the top level (login) shell, and .bashrc is for sub-shells. But I guess may bash users make their .bash_profile to have just one line

    source .bashrc



    PowerMacG4, PowerBookG4, iMac(C2D)   Mac OS X (10.4.8)  
  • Ken Nellis Level 2 Level 2
    expertise.macosx
    Mac OS X
    Good point. I mostly use Terminal, so forgot about this behavior. Seems like a good topic for a new thread: how to make Apple's X/xterm/bash play correctly together.