Table of Contents

You can color the output of any command using ANSI escape codes.

These are two examples:

echo -e "This is \033[31mred\033[0m"
d=`date`;echo -e "\033[31m$d\033[0m"
printf "\033[30;41mRed background, black text\033[0m"
  • You can use echo -e or printf.
  • The pattern for adding color is: \033[<FG ANSI code>;<BG ANSI code>m.
  • 31 is the ANSI code for foreground color red.
  • 0 resets the color.
Color nameForeground color codeBackground color code
black3040
red3141
green3242
yellow3343
blue3444
magenta3545
cyan3646
white3747
  • You can find more color codes on Wikipedia.
  • You can change the color of your terminal prompt by editing PS1 environment variable (on your .bashrc file for example).
[ricardo@myarch Documents]$ echo $PS1
[\u@\h \W]\$

{% include asciinema-script.html %}

If you have any suggestion, feel free to contact me via social media or email.