Shell colour codes

From Christoph's Personal Wiki
Revision as of 02:08, 9 October 2006 by Christoph (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In SuSE, the global configuration file for the colour ls utility /etc/DIR_COLORS. You can copy this file to .dir_colors in your $HOME directory to override the system defaults.

Colour codes

Below are the colour init strings for the basic file types. A colour init string consists of one or more of the following numeric codes:

  • Attribute codes:
 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
  • Text color codes:
 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
  • Background color codes:
 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

Bash shell colour codes

This following code echoes a bunch of colour codes to the terminal to demonstrate what's available. Each line is the colour code of one forground colour, out of 17 (default + 16 escapes), followed by a test use of that colour on all nine background colours (default + 8 escapes).

#!/bin/bash
T='gYw'   # The test text

echo -e "\n                 40m     41m     42m     43m\
     44m     45m     46m     47m";

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";
  done
  echo;
done
echo