Many commands determine whether to color their output using escape sequences by checking if their output file descriptor is a terminal.
This doesn't work very well when piping that output into a pager like more or less.
(Ideally UNIX folks would have created a way to determine if executables in a pipeline preserve color escape sequences and if the output fd at the very end of a pipeline was a tty or not. But they didn't.)
So many commands have an explicit command line option that can be used to specify that the color output should turned on, off, or be switched based on the immedita-output-fd type.
This is a collection of the common ones on a typical Linux (especially the GNU-centric distros) system.
Command | Color Option | Environment Variable |
---|---|---|
dmesg |
--color=always |
|
git [diff|log|show|status] |
--color=always |
|
gcc |
-fdiagnostics-color=always |
GCC_COLORS (SGR) |
grep |
--color=always |
GREP_COLORS (SGR) |
ls |
--color=always |
LS_COLORS (See: dircolors ) |
systemctl |
`` | SYSTEMD_COLORS (boolean) SYSTEMD_LOG_COLOR (boolean) |
tree |
-C |
|
`` | `` | `` |