Customizing the command line prompt in Mac OS X

You may have noticed that many Linux based machines has colored output for the ls command by default whereas Mac OS X based machines do not.

[edit] 1 Setting your terminal type in Terminal

If you are using Terminal on a Mac OS X computer you will have to set you terminal type. Select "Preferences..." from the Terminal menu and set the "Declare terminal type ($TERM) as:" option to xterm-color.

Note: Home and end keys will no longer work with this terminal type. If you want colors AND home/end, use the iTerm program as your terminal instead.


Restart your terminal to have this setting take effect.

[edit] 2 Creating the color and prompt settings

Open or create ~/.bash_profile (perhaps with nano) and adding these lines:

Warning: Add these commands at the end of the file and don't delete any existing text that might already be there, unless you know what you're doing!


export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

This will make directories blue and executables bold (see Unix file permissions).

You can also edit your shell prompt to make it stand out more. That's the little bit of text on the command line that appear before where you type. If you add this line to your ~/.bash_profile you can get the same prompt you get on Oceanus:

PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] "

Your prompt will be bold and look like this (if you use a black background like me):

ajohnson@oceanus ~/databases $

The first part stands for your username and the machine you are on, the second part is the 24 hour based time, and the last part contains your current directory. (See pwd.)

If you want the time included in your prompt, use this in your ~/.bash_profile:

PS1="\[\033[01;32m\]\u@\h \[\033[01;33m\]\t \[\033[01;34m\]\w \$\[\033[00m\] "

This prompt includes the twenty four hour based time:

ajohnson@oceanus 13:07:18 ~/databases $

After you have changed your ~/.bash_profile, you will either have to restart your terminal or type:

source ~/.bash_profile

[edit] 3 References

XHTML 1.1 CSS 2 Sec 508