Display text in color - Linux terminal

01 Mar 2015
Ever wanted to print text in colours? You can do it with ANSI escape characters. You can use ANSI codes in any programming language as long as the terminal supports it.

echo -e "\e[31mRed"

Red

echo -e "\e[32mGreen"

Green

Replace the number to get different colors. You can make text bold, italics, underline etc. Following is a short table describing several codes.

39     Default
30     Black     
31     Red   
32     Green   
33     Yellow   
34     Blue   
35     Magenta
36     Cyan   
37     Light gray   
97     White     

For a complete reference, link. (The page has a complete list of ANSI codes)