I understand ls
uses dircolors
to display colored output. dircolors
has default database of colors associated with file extensions, which can be printed wiht the command
dircolors --print-database
From man dir_colors
I read, the system-wide database should be located in /etc/DIR_COLORS
. But this file does not exist on my system (Debian). How can I modify system-wide color settings for dircolors
? Where does the command dircolors --print-database
take the settings from, when no file exists.
I am aware that user can have user-specific file ~/.dircolors
with his settings, but this is not suitable for me, since I need to change the settings for everybody.
A second questions is, whether it is possible to use 8-bit colors for dircolors. My terminal is xterm-256color
.
Best Answer
ls
takes it color settings from the environment variableLS_COLORS
.dircolors
is merely a convenient way to generate this environment variable. To have this environment variable take effect system-wide, put it in your shell's startup file.For
bash
, you'd put this in/etc/profile
:For
zsh
, you'd either put it in/etc/zshrc
or arrange forzsh
to read/etc/profile
on startup. Your distribution might havezsh
do that already. I just bring this up to point out that settingdircolors
for truly everybody depends on the shell they use.As for where
dircolors
gets its settings from, when you don't specify a file it just uses some builtin defaults.You can use
xterm
's 256 color escape codes in your dircolors file, but be aware that they'll only work forxterm
compatible terminals. They won't work on the Linux text console, for example.The format for 256 color escape codes is
38;5;colorN
for foreground colors and48;5;colorN
for background colors. So for example: