29

I found this image on the internet, but don't know how was it made,

enter image description here

Can anyone provide a sample on that? I just would like to have a color table as well.

1
  • You can find a collection of script for this in the ArchWiki.
    – aloisdg
    Jan 8, 2016 at 7:44

8 Answers 8

30

install the package named as:

colortest

and enjoy coloring by running the binaries like colortest-8 colortest-16 colortest-16b and so on

4
  • 3
    This answer probably refers to package in a specific Linux distribution. Where are the sources available for the other flavors of Unix?
    – raimue
    Nov 23, 2012 at 19:52
  • 1
    in debian/ubuntu: apt-get install colortest
    – roeland
    Aug 6, 2014 at 18:47
  • 1
    There's also colortest-256 included.
    – shrx
    Apr 5, 2016 at 9:24
  • 1
    Is there a version of this for macOS? We don't have apt-get over here πŸ™‚
    – Ky.
    Mar 13, 2019 at 22:20
22

The escape sequence ESC [ SPEC1 ; … m changes the text attributes (color, bold, etc.) of subsequently written characters. This is one of the ANSI terminal escape sequences. Each SPEC can be one of the following (the list is not exhaustive):

  • 0 to switch to the default colors.
  • 1 to turn boldface on.
  • 30 through 37 to set the foreground color (black, red, green, yellow, blue, magenta, cyan, gray).
  • 40 through 47 to set the background color (same list).

Here's a shell snippet that outputs almost what you posted.

printf "          "
for b in 0 1 2 3 4 5 6 7; do printf "  4${b}m "; done
echo
for f in "" 30 31 32 33 34 35 36 37; do
    for s in "" "1;"; do
        printf "%4sm" "${s}${f}"
        printf " \033[%sm%s\033[0m" "$s$f" "gYw "
        for b in 0 1 2 3 4 5 6 7; do
            printf " \033[4%s;%sm%s\033[0m" "$b" "$s$f" " gYw "
        done
        echo
     done
done
1
  • 1
    colortest is nice, but this answer gives exactly what the original asker asked for. it's also nice to see the color codes on the screen. saves thinking about it.
    – pdwalker
    Aug 3, 2017 at 6:27
11

While it's not that hard to replicate, your screenshot likely came from tldp.org; the bottom of that page contains a script that outputs the table you see:

To help myself remember what colours are available, I wrote a script that output all the colours to the screen. Daniel Crisman has supplied a much nicer version which I include below:

#!/bin/bash
#
#   This file echoes a bunch of color codes to the 
#   terminal to demonstrate what's available.  Each 
#   line is the color code of one forground color,
#   out of 17 (default + 16 escapes), followed by a 
#   test use of that color on all nine background 
#   colors (default + 8 escapes).
#

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

There's a similar table available as a demo in the F-ANSI library:

ANSI color table generated by F-ANSI

1
  • 2
    This is the exact answer to the question.
    – wisbucky
    Feb 23, 2017 at 1:01
10

There are a few variations, well six to be precise, listed on the Arch Wiki Xresouces page.

As well as the one that is used in your screenshot, there are some more inventive ones—my favourite of which is from the Crunchbang forums and features space invaders:

#!/bin/bash
#
# ANSI color scheme script featuring Space Invaders
#
# Original: http://crunchbanglinux.org/forums/post/126921/#p126921
# Modified by lolilolicon
#

f=3 b=4
for j in f b; do
  for i in {0..7}; do
    printf -v $j$i %b "\e[${!j}${i}m"
  done
done
bld=$'\e[1m'
rst=$'\e[0m'

cat << EOF

 $f1  β–€β–„   β–„β–€     $f2 β–„β–„β–„β–ˆβ–ˆβ–ˆβ–ˆβ–„β–„β–„    $f3  β–„β–ˆβ–ˆβ–„     $f4  β–€β–„   β–„β–€     $f5 β–„β–„β–„β–ˆβ–ˆβ–ˆβ–ˆβ–„β–„β–„    $f6  β–„β–ˆβ–ˆβ–„  $rst
 $f1 β–„β–ˆβ–€β–ˆβ–ˆβ–ˆβ–€β–ˆβ–„    $f2β–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆ   $f3β–„β–ˆβ–€β–ˆβ–ˆβ–€β–ˆβ–„   $f4 β–„β–ˆβ–€β–ˆβ–ˆβ–ˆβ–€β–ˆβ–„    $f5β–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆ   $f6β–„β–ˆβ–€β–ˆβ–ˆβ–€β–ˆβ–„$rst
 $f1β–ˆβ–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–ˆ   $f2β–€β–€β–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–€β–€   $f3β–€β–ˆβ–€β–ˆβ–ˆβ–€β–ˆβ–€   $f4β–ˆβ–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–ˆ   $f5β–€β–€β–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–€β–€   $f6β–€β–ˆβ–€β–ˆβ–ˆβ–€β–ˆβ–€$rst
 $f1β–€ β–€β–„β–„ β–„β–„β–€ β–€   $f2 β–€β–ˆβ–„ β–€β–€ β–„β–ˆβ–€    $f3β–€β–„    β–„β–€   $f4β–€ β–€β–„β–„ β–„β–„β–€ β–€   $f5 β–€β–ˆβ–„ β–€β–€ β–„β–ˆβ–€    $f6β–€β–„    β–„β–€$rst

 $bld$f1β–„ β–€β–„   β–„β–€ β–„   $f2 β–„β–„β–„β–ˆβ–ˆβ–ˆβ–ˆβ–„β–„β–„    $f3  β–„β–ˆβ–ˆβ–„     $f4β–„ β–€β–„   β–„β–€ β–„   $f5 β–„β–„β–„β–ˆβ–ˆβ–ˆβ–ˆβ–„β–„β–„    $f6  β–„β–ˆβ–ˆβ–„  $rst
 $bld$f1β–ˆβ–„β–ˆβ–€β–ˆβ–ˆβ–ˆβ–€β–ˆβ–„β–ˆ   $f2β–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆ   $f3β–„β–ˆβ–€β–ˆβ–ˆβ–€β–ˆβ–„   $f4β–ˆβ–„β–ˆβ–€β–ˆβ–ˆβ–ˆβ–€β–ˆβ–„β–ˆ   $f5β–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆ   $f6β–„β–ˆβ–€β–ˆβ–ˆβ–€β–ˆβ–„$rst
 $bld$f1β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€   $f2β–€β–€β–€β–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–€β–€β–€   $f3β–€β–€β–ˆβ–€β–€β–ˆβ–€β–€   $f4β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€   $f5β–€β–€β–€β–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–€β–€β–€   $f6β–€β–€β–ˆβ–€β–€β–ˆβ–€β–€$rst
 $bld$f1 β–„β–€     β–€β–„    $f2β–„β–„β–€β–€ β–€β–€ β–€β–€β–„β–„   $f3β–„β–€β–„β–€β–€β–„β–€β–„   $f4 β–„β–€     β–€β–„    $f5β–„β–„β–€β–€ β–€β–€ β–€β–€β–„β–„   $f6β–„β–€β–„β–€β–€β–„β–€β–„$rst


                                     $f7β–Œ$rst

                                   $f7β–Œ$rst

                              $f7    β–„β–ˆβ–„    $rst
                              $f7β–„β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–„$rst
                              $f7β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€$rst

EOF

spacey

2
  • 1
    I like this figure, but SHW provided the exact script, I'll pick his answer ;-P
    – daisy
    Jun 29, 2012 at 1:55
  • 2
    Fair enough: the wiki page I linked to also includes the script in your screenshot; I just think this is a more interesting way to display X colours :)
    – jasonwryan
    Jun 29, 2012 at 2:10
7
echo -e "\n\033[4;31mLight Colors\033[0m \t\t\t  \033[1;4;31mDark Colors\033[0m"
echo -e " \e[0;30;47m Black     \e[0m   0;30m \t\t \e[1;30;40m Dark Gray   \e[0m  1;30m"
echo -e " \e[0;31;47m Red       \e[0m   0;31m \t\t \e[1;31;40m Dark Red    \e[0m  1;31m"
echo -e " \e[0;32;47m Green     \e[0m   0;32m \t\t \e[1;32;40m Dark Green  \e[0m  1;32m"
echo -e " \e[0;33;47m Brown     \e[0m   0;33m \t\t \e[1;33;40m Yellow      \e[0m  1;33m"
echo -e " \e[0;34;47m Blue      \e[0m   0;34m \t\t \e[1;34;40m Dark Blue   \e[0m  1;34m"
echo -e " \e[0;35;47m Magenta   \e[0m   0;35m \t\t \e[1;35;40m Dark Magenta\e[0m  1;35m"
echo -e " \e[0;36;47m Cyan      \e[0m   0;36m \t\t \e[1;36;40m Dark Cyan   \e[0m  1;36m"
echo -e " \e[0;37;47m Light Gray\e[0m   0;37m \t\t \e[1;37;40m White       \e[0m  1;37m"

and so on.

1

This script seems to be the one that produced the picture.

2
  • Welcome to U&L.SE. Nice Catch btw
    – eyoung100
    Sep 15, 2014 at 18:48
  • 1
    That script was (almost certainly) sourced from tlpd.org.
    – dimo414
    Feb 23, 2017 at 1:41
0

I'm not sure if this is exact answer, but at http://linuxcommand.org/lc3_adv_tput.php I found several functions testing tput for colorizing BASH.

#!/bin/bash

echo "tput colors test"
echo "================"
echo
echo "tput setaf/setab [0-9] ... tput sgr0"
echo

for fg_color in {0..7}; do
  set_foreground=$(tput setaf $fg_color)
  for bg_color in {0..7}; do
    set_background=$(tput setab $bg_color)
    echo -n $set_background$set_foreground
    printf ' F:%s B:%s ' $fg_color $bg_color
  done
  echo $(tput sgr0)
done

echo
echo "END"
echo
exit
0
cat "$0" 1>&2;
#
# = Coloring test utility =
#
# [
# |*| Source: https://unix.stackexchange.com/a/643536
# |*| Source (original): https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
# |*| Last update: CE 2021-08-18 06:29 UTC ]
#
#
# [ Caveat:
#
# The description below has insufficient coverage on the subject. (and part of which may be outright misleading)
#
# Check # References for a complete view. ]
#
#
# This script shall echo a bunch of color codes: demonstrating the coloring compatibility of the shell / terminal.
#
# Each output line of interest would consist of:
# |*| The literal color code itself: of 1 foreground (font) color, out of the 17 (default + 16 escapes).
# |*| Followed by its testcase: with all of the 9 background colors (default + 8 escapes).
#
#
#
#
# == Implementation ==
#
# Testcase text:
    text='gYw';

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

    for FGs in \
    '  [0;m' \
    '[1;37m' \
    '[0;30m' \
    '[1;30m' \
    '[0;31m' \
    '[1;31m' \
    '[0;32m' \
    '[1;32m' \
    '[0;33m' \
    '[1;33m' \
    '[0;34m' \
    '[1;34m' \
    '[0;35m' \
    '[1;35m' \
    '[0;36m' \
    '[1;36m' \
    '[0;37m';

    do {
    FG="${FGs//[[:space:]]/""}";
    echo -nE "$FGs ";
    echo -ne '\e'$FG;
    echo -nE "  $text  ";

    for BG in \
    '[40m' '[41m' '[42m' '[43m' '[44m' '[45m' '[46m' '[47m';

    do
    echo -nE ' ';
    echo -ne '\e'$FG'\e'$BG; # [Note 1]
    echo -nE "  $text  ";
    echo -ne '\e[m'; # [Note 2]

    done;

    echo;
    };

    done;

    unset text FGs FG BG;
    echo;
#
#
#
#
# == Notes & References ==
#
#
# === Notes ===
#
# [Note 1]
# [
# Note the order may not be inverted: setting the foreground color ("$FG") may reset the background color ("$BG").
#
# Check ANSI escape sequence # CSI [1], and [ https://misc.flogisoft.com/bash/tip_colors_and_formatting#attributes_combination ] [3] for details. ]
#
#
# [Note 2]
# [
# There are also some other formatting codes not included in the table but may be used to alter the text's appearance:
#
# |*| '\e[1m': Bold
# |*| '\e[2m': Dim
# |*| '\e[4m': Underlined
# |*| '\e[5m': Blink
# |*| '\e[7m': Inverse color
# |*| '\e[8m': Hidden
# |*| '\e[9m': Strikethrough ]
#
#
# === References ===
#
# [1]
# [
# |*| ANSI escape sequence ## CSI; SGR; Examples:
# [
# |*| https://en.wikipedia.org/wiki/ANSI_escape_code#CSI
# |*| https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
# |*| https://en.wikipedia.org/wiki/ANSI_escape_code#Examples ] ]
#
#
# [2]
# [
# |*| Unix formatting code (Google Search): https://www.google.com/search?hl=en&gl=us&q=Unix+formatting%7Ccolor+code ]
#
#
# [3]
# [
# |*| Colors and formatting (ANSI/VT100 Control sequences): https://misc.flogisoft.com/bash/tip_colors_and_formatting ]
#
#
#
#
# == See also ==
#
# |*| 256-color test: https://unix.stackexchange.com/a/643715
#

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.