dircolors: modify color settings globaly

ls takes it color settings from the environment variable LS_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:

# `dircolors` prints out `LS_COLORS='...'; export LS_COLORS`, so eval'ing
# $(dircolors) effectively sets the LS_COLORS environment variable.

eval "$(dircolors /etc/DIR_COLORS)"

For zsh, you'd either put it in /etc/zshrc or arrange for zsh to read /etc/profile on startup. Your distribution might have zsh do that already. I just bring this up to point out that setting dircolors 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 for xterm 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 and 48;5;colorN for background colors. So for example:

.mp3  38;5;160                   # Set fg color to color 160      
.flac 48;5;240                   # Set bg color to color 240
.ogg  38;5;160;48;5;240          # Set fg color 160 *and* bg color 240.
.wav  01;04;05;38;5;160;48;5;240 # Pure madness: make bold (01), underlined (04), blink (05), fg color 160, and bg color 240!

Where does the command dircolors --print-database take the settings from, when no file exists.

As per the manual, it uses a precompiled database in the absence of a file.

If file is specified, dircolors reads it to determine which colors to use for which file types and extensions. Otherwise, a precompiled database is used. For details on the format of these files, run ‘dircolors --print-database’.

In order to change the settings for everybody, you could create a /etc/dircolors file and add the following to /etc/bashrc:

d=/etc/dircolors
test -r $d && eval "$(dircolors $d)"

Linux set console background colors with dircolors:

Your dircolors file controls the colors for words that appear through ls on the console. Find this .dircolors file for your distribution, a link to help:

http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html

For me on Fedora 17, my dircolors file is: /etc/DIR_COLORS

Copy /etc/DIR_COLORS into your /home/el/.dircolors directory. Create it if it doesn't exist.

Edit /home/el/.dircolors, look for the text "dir".

Change this:

DIR 01;34   # directory

To this:

DIR 01;36   # directory

Save and close and restart the shell. The directories go from dark blue on black (unreadable) to bright teal on black (readable).

Tags:

Colors

Bash

Ls