Skip to main content
footnote
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272

You can see the colors in this chart1 as they would appear on your terminal fairly easily:

Although this is not a great example if you are happy with using bash's special \d or \D{format} prompt escapes -- which are not the topic of the question but can be found in man bash under PROMPTING. There are various other useful escapes such as \w for current directory, \u for current user, etc.


1. The main portion of this chart, colors 16 - 231 (notice they are not in numerical order) are a 6 x 6 x 6 RGB color cube. "Color cube" refers to the fact that an RGB color space can be represented using a three dimensional array (with one axis for red, one for green, and one for blue). Each color in the cube here can be represented as coordinates in a 6 x 6 x 6 array, and the index in the chart calculated thusly:

 16 + R * 36 + G * 6 + B 

The first color in the cube, at index 16 in the chart, is black (RGB 0, 0, 0). You could use this formula in shell script:

#!/bin/sh function RGBcolor { echo "16 + $1 * 36 + $2 * 6 + $3" | bc } fg=$(RGBcolor 1 0 2) # Violet bg=$(RGBcolor 5 3 0) # Bright orange. echo -e "\\033[1;38;5;$fg;48;5;${bg}mviolet on tangerine\\033[0m" 

You can see the colors in this chart as they would appear on your terminal fairly easily:

Although this is not a great example if you are happy with using bash's special \d or \D{format} prompt escapes -- which are not the topic of the question but can be found in man bash under PROMPTING. There are various other useful escapes such as \w for current directory, \u for current user, etc.

You can see the colors in this chart1 as they would appear on your terminal fairly easily:

Although this is not a great example if you are happy with using bash's special \d or \D{format} prompt escapes -- which are not the topic of the question but can be found in man bash under PROMPTING. There are various other useful escapes such as \w for current directory, \u for current user, etc.


1. The main portion of this chart, colors 16 - 231 (notice they are not in numerical order) are a 6 x 6 x 6 RGB color cube. "Color cube" refers to the fact that an RGB color space can be represented using a three dimensional array (with one axis for red, one for green, and one for blue). Each color in the cube here can be represented as coordinates in a 6 x 6 x 6 array, and the index in the chart calculated thusly:

 16 + R * 36 + G * 6 + B 

The first color in the cube, at index 16 in the chart, is black (RGB 0, 0, 0). You could use this formula in shell script:

#!/bin/sh function RGBcolor { echo "16 + $1 * 36 + $2 * 6 + $3" | bc } fg=$(RGBcolor 1 0 2) # Violet bg=$(RGBcolor 5 3 0) # Bright orange. echo -e "\\033[1;38;5;$fg;48;5;${bg}mviolet on tangerine\\033[0m" 
added image title
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

Those are ANSI escape sequences; that link is to a chart of color codes but there are other interesting things on that wikipediaWikipedia page as well. Not all of them work on (e.g.) a normal linuxLinux console.

enter image description herexterm 256 color chart

Those are ANSI escape sequences; that link is to a chart of color codes but there are other interesting things on that wikipedia page as well. Not all of them work on (e.g.) a normal linux console.

enter image description here

Those are ANSI escape sequences; that link is to a chart of color codes but there are other interesting things on that Wikipedia page as well. Not all of them work on (e.g.) a normal Linux console.

xterm 256 color chart

added 481 characters in body
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272

Also note that if you want to include the output of a command run every time the prompt is used (as opposed to just once when the prompt is set), you should set it as a literal string with single quotes, e.g.:

PS1='\[\033[01;32m\]$(date): \[\033[0m\]' 

Although this is not a great example if you are happy with using bash's special \d or \D{format} prompt escapes -- which are not the topic of the question but can be found in man bash under PROMPTING. There are various other useful escapes such as \w for current directory, \u for current user, etc.

Also note that if you want to include the output of a command run every time the prompt is used (as opposed to just once when the prompt is set), you should set it as a literal string with single quotes, e.g.:

PS1='\[\033[01;32m\]$(date): \[\033[0m\]' 

Although this is not a great example if you are happy with using bash's special \d or \D{format} prompt escapes -- which are not the topic of the question but can be found in man bash under PROMPTING. There are various other useful escapes such as \w for current directory, \u for current user, etc.

added 892 characters in body
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272
Loading
Added stuff about $TERM and setting 256 color prompt
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272
Loading
remove accidental $ in export
Source Link
phemmer
  • 73.9k
  • 21
  • 199
  • 231
Loading
added 327 characters in body
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272
Loading
added 1096 characters in body
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272
Loading
added 1096 characters in body
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272
Loading
Source Link
goldilocks
  • 90k
  • 33
  • 212
  • 272
Loading