Here is a little tip so that you can quickly tell which linux machine that you are currently logged into. The easy way to do this is to colour code the shell prompt.

In bash the PS1 enviroment variable controls how the prompt is formatted. On a debian squeeze install it would be set to something like this by default

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

That of course does look somewhat confusing mostly because of the escaping. The letters with a '\' at the front are telling bash to also display certain things but I will cover that in another post. Lets add some colour.

To add some colour we need to add a control sequence to the shell prompt this tells the terminal to enable a specific colour then at the end of the prompt turn that colour back to the default for the terminal.

To set the colour we need to apply this to the beginning of the environment variable (this is using the color red 31m)

\[\033[31m\]

Then we also need to append the close sequence to the end of the environment variable.

\[\033[0m\]

So the complete environment variable should now look like this.

export PS1="\[\033[31m\]\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$\[\033[0m\]"

Our prompt will be red. To change the colour you only need to change the starting sequence and choose from one of the following colours.

Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33
Light Gray 0;37

Dark Gray 1;30
Light Blue 1;34
Light Green 1;32
Light Cyan 1;36
Light Red 1;31
Light Purple 1;35
Yellow 1;33
White 1;37





Last Modified: 12 December 2016

Releated Posts


2013-03-01 - Linux - What and how to kill a zombie process
2013-02-14 - Linux - Getting sshfs to work
2012-12-12 - Linux - List / Copy group membership for users
2012-12-08 - Linux - ssh key authentication
2012-12-04 - Linux - sudo without a password
2012-10-13 - Rasberry Pi - Alternative method to play video without omx gstreamer element
2012-10-10 - How to run tcpdump as root
2012-07-13 - Linux - Killing all processes for a specific user
2012-04-05 - Using gdb to debug a core file
2012-01-16 - Linux - Color Coding The Bash Prompt
2012-01-14 - Linux - Automatically set the DISPLAY environment variable in SSH connection
2012-01-06 - Adding extra swap space to linux