Hack 37. Change foreground color of the prompt

by Ramesh

Display prompt in blue color, along with username, host and current directory information

  1. $ export PS1="\e[0;34m\u@\h \w> \e[m "
  2.  
  3. [Note: This is for light blue prompt]
  4.  
  5. $ export PS1="\e[1;34m\u@\h \w> \e[m "
  6.  
  7. [Note: This is for dark blue prompt]
  • \e[ – Indicates the beginning of color prompt
  • x;ym – Indicates color code. Use the color code values mentioned below.
  • \e[m – indicates the end of color prompt

Color Code Table:

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

[Note: Replace 0 with 1 for dark color]

Make the color change permanent by adding the following lines your ~/.bash_profile or ~/.bashrc

  1. $ vi ~/.bash_profile
  2.  
  3. STARTCOLOR='\e[0;34m';
  4. ENDCOLOR="\e[0m"
  5. export PS1="$STARTCOLOR\u@\h \w> $ENDCOLOR"