CS W1007x (Section 001) Introduction to Computer Science - Fall 1997
Handout #09: September 25, 1997

Customizing your UNIX prompt


Ever "cd" around and eventually forget which directory you're in? You'd probably do an "ls" or "pwd" to regain your bearings right? Here's a typical scenario:

---------------------------------------
$ cd src
$ ls
  3101-1  3101-2  3139    3156    3824
$ cd 3101-1
$ ls
  hw1     hw2     hw3     hw4
$ cd hw1
$ cd ../
$ cd /
$ cd /etc
$ cd ~tt70
$ cd src
---------------------------------------

Having just the "$" as your prompt, isn't all too helpful is it? Now, check out what happens when you have a smarter prompt:

---------------------------------------
$ tt70@vanakam | /h/u2/t/tt70=>cd src
$ tt70@vanakam | /amd/hola/h/u2/t/tt70/src=>ls
3101-1  3101-2  3139    3156    3824
$ tt70@vanakam | /amd/hola/h/u2/t/tt70/src=>cd 3101-1
$ tt70@vanakam | /amd/hola/h/u2/t/tt70/src/3101-1=>ls
hw1     hw2     hw3     hw4
$ tt70@vanakam | /amd/hola/h/u2/t/tt70/src/3101-1=>cd hw1
$ tt70@vanakam | /amd/hola/h/u2/t/tt70/src/3101-1/hw1=>cd ../
$ tt70@vanakam | /amd/hola/h/u2/t/tt70/src/3101-1=>cd /
$ tt70@vanakam | /=>cd /etc
$ tt70@vanakam | /etc=>cd ~tt70
$ tt70@vanakam | /h/u2/t/tt70=>cd src
$ tt70@vanakam | /h/u2/t/tt70/src=>
---------------------------------------

Notice how the prompt shows my current directory? it's like having "pwd" built into my prompt. Actually, that's what it is. Here's how you can change your "$" prompt to something like what I have above:
  1. "cd" to your home directory (cd ~)
  2. Edit the file called ".profile" with emacs. You've worked with ".profile" before. Recall that you had to add a new PATH to the ".profile" for HW #1.
  3. Add these lines to your ".profile":
    
       export HOST=`hostname | cut -f1 -d"."`
       export ME=`whoami`
       export PS1='\$ $ME@$HOST | $PWD=>'
    
    
    The first line defines a variable that contains the name of the computer on which you are currently logged in. In my example, I was logged on to the computer called "vanakam."

    The second line is a variable that holds your current login name. This may not be so helpful if you have only one account. (I have tt70@columbia.edu, ta-tt70@columbia.edu, and thai@cs.columbia.edu, so i sometimes forget which account I am using.)

    The third line puts things all together. "PS1" is what UNIX calls your prompt. By default, it is set to "$". Notice the $PWD variable in the third line. We didn't have to explicitly define this one because UNIX already does it. Feel free to play around with this line. You can add your own stuff, or removed any part that I have (like the "$ME" part if you don't think it's helpful).

  4. Log out and log back in so your new ".profile" can take effect.
Good luck and have fun!
kos@cs.columbia.edu
(Thanks to Tom for creating this handout!)