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"
  • You can use echo -e or printf.
  • The pattern for adding color is: \033[<ANSI code>m.
  • 31 is the ANSI code for foreground color red.
  • 0 resets the color.
Color name Foreground color code Background color code
black 30 40
red 31 41
green 32 42
yellow 33 43
blue 34 44
magenta 35 45
cyan 36 46
white 37 47
  • You can find more color codes on Wikipedia.