As a user or administrator of multiple Linux systems, it is important that you pay very close attention as to what box you are about to issue a command on. One powerful way to do that is to use a distinct font and/or background color for each server. This example assumes that you are using the default bash shell on a Red Hat Linux system.
1) Edit the /etc/bashrc using your favorite editor.
2) Search for the string, PROMPT until you reach a statement that looks like:
PROMPT_COMMAND=’echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"’
3) Insert the string \e[34;1m at the location shown below:
PROMPT_COMMAND='echo -ne "\e[34;1m\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"’
4) Save the file.
5) Run the command source /etc/bashrc.
By changing the value after the \e[ you can change the font color. Here is a color list for the font (foreground):
31 = Red
32 = Green
33 = Yellow
34 = Blue
35 = Purple
36 = Aqua
37 = White
The value in the ;1m portion of the string makes the prompt bright. Alternatively, you can change the value in that portion of the string to change the background color. Here is a list of background colors:
40 = Black
41 = Red
42 = Green
43 = Yellow
44 = Blue
45 = Purple
46 = Aqua
47 = White
If you do want a colored background, one good color choice might be a yellow font on a blue background: \e[33;44m
If you are using a system other than Red Hat and don’t have an /etc/bashrc file, a good technique for knowing where to insert the prompt is to change to the /etc directory and issue the command grep PROMPT * – that will give you a clue as to where the system’s default prompt is being set.
You can also override just single user’s prompt by editing ~/.bashrc and inserting a similar PROMPT_COMMAND= statement into that file.