A few words of thanks would be greatly appreciated.

Changing the color of the command prompt(shell)


Changing the color of characters in the prompt (or shell), make them more readable. If you are using colors group, you can sense by color, this will eliminate the risk of having a lengthy command prompt.

Information that can be transmitted by the colors

You can assign the green commands for a first machine (host) and blue for another, or green when the system is not loaded, yellow when resources are used or you choose a color for root prompt, another for an MC ...


Two methods are available are possible. The most used (but the less effective) is to insert escape characters. The following shows the chain commands in blue:

$ PS1="[\033[0;34m][u@h][\033[0m]"

This method has two major drawbacks: its syntax is unreadable, so prone to entry errors, and it is only applicable if the terminal window supports ANSI escape sequence,

Using tput

  • changing color of the prompt(or shell) using tput, your definitions are portable to other terminal emulators.
$ BLUE=$ (tput setaf 4)
$ BLACK=$ (tput setaf 0)
$ PS1=" [$BLUE] u@h]  [$BLACK] "
  • Understanding these lines
  • tput is firstly used to define a variable that contains the sequence of characters to force the color to blue.
  • The second line did the same for black.It is now necessary to know the escape sequences, since tput manages a correspondence file descriptions to all terminals file to consult to find the appropriate sequence terminal physical or emulated.
  • The third line, finally, uses both variable and $ $ BLUE BLACK in the definition of the $ PS1 prompt


  • Note: You can view a complete list of commands man tput and man terminfo.

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Changing the color of the command prompt(shell) », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).