Sunday, 6 February 2011

A colourful command prompt in bash

A command prompt is very important in a UNIX / Linux environment. The best thing about it, is that it is fully customizable. The one I find most useful at the moment is this:

export PS1="\[\033[1;34m\][ \[\033[1;32m\]\\u\[\033[1;34m\] @ \[\033[1;32m\]\\h\[\033[1;33m\] \\w \[\033[1;34m\]] \! \$\[\033[0m\] "

That line can be executed from a command line, or added to the bottom of the .bashrc file that is each user's home directory. If you add it to the .bashrc file, then you will need to exit your session, and log back into the machine. The results are to colourize the command line with the username, the hostname, the location of the current directory, and the number of the command about to be executed.

The results are:
Colourful command prompt in bash

[ ric_man @ mymachine ~ ] 75 $

In the case of a user that has elevated privileges, you may be interested in change the colours of the command prompt - like making it all red if the user is the administrator, or the box is a production machine. Refer to a this page with a list of bash colours for more ideas.

1 comment:

  1. Well Very useful.. Got tired of boring, dull sh1tty terminal.. Now I have the colourful one..

    Thanks Ric :)