Today I’d like to put into my notes the config I use in order to customize the bash shell prompt. This is with no doubt an extra, probably you’ll never need this.. until the day you realize that working on several remote systems at the same time can be confusing, and confusion leads to mistakes.

That’s why one day I found customizing the bash shell prompt very useful and sticked with it.

Prompt customization works by setting the PS1 variable according to the following options:

\u = username
\h = hostname
\H = full hostname (eg. ‘localhost.localdomain’)
\w = full path (eg. ‘/etc/rc3.d’)
\W = current working directory (eg. just ‘rc3.d’)
$ = # or $
\d = date
\l = current terminal (eg. ‘tty2’)
While here are the COLOR CODES:
30m => black
31m => red
32m => green
33m => yellow
34m => blue
35m => purple
36m => cyan
37m => white

The prompt I’m feeling comfortable to use is..

  • coloured: because I want to visually distinguish servers
  • full path: because I found it very useful to know where I am, or maybe to copy the path just highlighting it with the mouse
  • on two rows: because long paths may eat too much columns

Here's how a prompt with these requirements looks like:
(Notice the COLOR CODE placeholder)  

fancy prompt

Copy and paste the following code on your bashrc file to obtain a prompt like the one shown above:

export PS1='[\u@\h \[\033[01;35m\]\w \[\033[00m\]]\n\$ '

Edit: here you can find a lengthy guide to shell prompt customization by IBM