In this example we are going to change terminal prompt colour. Having different colours for different users and servers can be useful. Having the same colour for all users and servers might sometimes cause people doing wrong things with wrong users and on wrong servers. Colours will tell us who we are and where we are.



Colouring terminal prompt ubuntu@linux:~$ is done with a special string which looks like the one below.


The \[\033[1;32m\]\ part is used for colouring and placed in front of u, h, w and $. The last \ is not used for @ and : signs.


It is done with 1;32m which represents colour pair (x;y).

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





Changing colour profile

After changing colours, you will need to either exit terminal or open a new terminal to see the changes.


  1. Open up ~/.bashrc file.

  2. Find #force_color_prompt=yes line and uncomment it by removing # sign.

  3. Find if [ "$color_prompt" = yes ]; then, change the colour string and save the changes.


Create a .bash_profile file with the content below.

inanzzz@macos:~$ nano ~/.bash_profile

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '


Create and run bash script below to list all available colours and their codes.



while [ $color -lt 245 ]; do
echo -e "$color: \033[38;5;${color}mhello\033[48;5;${color}mworld\033[0m"