Torn as I now am between my iMac and my laptop (Ubuntu linux), I invariably find myself using both: OS X at the desk, Ubuntu on the couch. My brief tenure in linuxland taught me to embrace the CLI (Command Line Interface), and upon returning to mactopia, I find I use the CLI almost exclusively. (That and VIM. I decided early on that rather than waste time learning yet another GUI editor, I’d take the opportunity to learn VIM and promptly fell in love. I’m typing this in VIM right now, even as my TextMate icon stares up at me from the dock.) For me, Linux and Darwin are sufficiently similar that I’m at home on either and I’ve come to respect their subtle differences.
That said, one thing I really liked about the default bash terminal in Ubuntu was its color, so I sought to bring this feature over to my OS X Terminal. Using ls with color makes things faster—colors can tell you about files in ways that ls -F never could. To enable this in OS X (bash), you’ll need to add some options to your .profile:
export CLICOLOR=1 export TERM=xterm-color
The first line turns on color, and the second ensures that your terminal is declared as color capable. While this will work as advertised, it won’t necessarily look very good if you use a dark background. By default, directories are listed in blue, and while this looks good in Ubuntu it’s just too dark on the Mac. For those of us who rock a black background, you might want to change the ls colors.
export LSCOLORS=gxfxcxdxbxegedabagacad # cyan directories
In the above example, I’m using cyan for directories; this is a fair compromise and looks nice in both OS X and Ubuntu. If you want to know about each of the color codes above, they’re listed in the ls manual (man ls).
For the complete linux effect on OS X, a green prompt will also be necessary. Without getting in the sordid details of customizing your prompt (it’s a long and arduous tale that I’ll save for another article), I offer this:
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '
When we put it all together, we get a comfortable and portable CLI that looks quite nice, no matter where you’re logging in from.
# colors export CLICOLOR=1 export TERM=xterm-color export LSCOLORS=gxgxcxdxbxegedabagacad # cyan directories export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '


Very cool. I’m working on getting more comfortable with CLI, being a long time mac user. This certainly makes things easier.
Maybe you can answer a related question for me (which I’ve googled over and over to no avail): On OS X we are typically directed to put PATH and stuff like that into
~/.bash_profile. I’ve also seen.bash_loginand now you refer to.profile. I’m wondering what the difference is between these. It seems that if.bash_profileexists all others are ignored. This is particularly annoying for things like$PATH. I find myself wanting to add/usr/local/bin(et al) to a$PATHthat not only I will use in CLI but also be picked up by daemons and shell scripts that get run at startup or with no logged-in user. Where should I put this stuff? Should I just choose one (.bashprofile,.bash_login, or.profile) and stick with it?Thanks again for the post
Good question. Actually, there’s no difference between
.bash_profile,.bash_loginand.profilesave for the load-order. Bash tries to load.bash_profilefirst, then.bash_login, and finally, if it’s still coming up empty,.profile. Once it finds a candidate it stops looking, so any others (as you noticed) are ignored.So yeah, your best bet is to pick one and stick with it. I like to use
.profilebecause it’s shorter to type and I’m lazy.For system-wide settings, there is a global profile that will get run for any shell (sh, bash, etc.) which you’ll find in
/etc/profile. If you set a$PATHvariable there, it will be accessible system-wide.Thanks! One of the great mysteries finally explained!