Colored console (Bash)

From Rosalab Wiki
Revision as of 17:47, 7 June 2012 by D uragan (Talk | contribs) (translated from Russian)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

When working in console, one can note that it is sometimes not easy to analyze output of different programs. Users can also claim about bad visual delimitation between prompt and text area. To solve this issues, we recommend to use colors to highlight console output.

Remember that in any system we have at least two users: 1 - the root one and 2 - normal user himself. For different users, you should edit different configuration files.

User console

In order to get a colored prompt in user's console, go to home folder, open the (hidden) .bashrc file and add the following lines there:

#PS1='[\u@\h \W]\$ '
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] '

Save the file, relaunch console and enjoy the colors:

Bash-color1.png

Root console

In order to get a colored prompt in root console, launch console under the root use, open the /root/.bashrc file and add the following lines there:

#PS1='[\u@\h \W]\$ '
PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] '

Save the file, relaunch console and enjoy the colors:

Bash-color2.png

About colors

Short list of colors used:

'\e[0;30m' - Black
'\e[0;31m' - Red
'\e[0;32m' - Green
'\e[0;33m' - Yellow
'\e[0;34m' - Blue
'\e[0;35m' - Purple
'\e[0;36m' - Turquoise
'\e[0;37m' - White