dircolors
Configure color settings for directory listings
TLDR
Output commands to set LS_COLOR using default colors
Display each filetype with the color they would appear in ls
Output commands to set LS_COLOR using colors from a file
Output commands for Bourne shell
Output commands for C shell
View the default colors for file types and extensions
SYNOPSIS
dircolors [OPTION]... [FILE]
PARAMETERS
--print-database
Prints the default DIR_COLORS database built into the command. This output can be used as a template for custom configuration files.
--bourne-shell
--sh
Output commands suitable for Bourne-compatible shells (e.g., Bash, Zsh). This is the default behavior.
--c-shell
--csh
Output commands suitable for C-shell compatible shells (e.g., csh, tcsh).
--default
Use the built-in default color scheme rather than trying to read a configuration file from /etc/DIR_COLORS or the user's home directory.
FILE
Specify an alternative configuration file to read instead of the default /etc/DIR_COLORS or ~/.dircolors.
--help
Display a help message and exit.
--version
Output version information and exit.
DESCRIPTION
The dircolors command generates shell code to set the LS_COLORS environment variable. This variable is then used by the ls command (specifically with its --color option) to display files and directories in various colors based on their type, permissions, and other attributes. Users typically configure dircolors by creating a configuration file, often ~/.dircolors, which defines the specific colors for different file types (e.g., directories, executable files, archives, symbolic links).
When executed, dircolors reads its configuration (either from a specified file, /etc/DIR_COLORS, or its built-in defaults) and outputs a series of shell commands. These commands, when evaluated in a shell startup script like .bashrc or .zshrc, populate the LS_COLORS variable, enabling a visually rich and informative directory listing. It supports both Bourne-compatible shells (like Bash and Zsh) and C-shell syntax.
CAVEATS
The output of dircolors must be evaluated by the shell for the LS_COLORS variable to be set. Simply running dircolors alone will print the commands to standard output but won't apply them to the current shell session.
For colors to appear, the ls command itself must be invoked with the --color option (e.g., ls --color=auto or via an alias like alias ls='ls --color=auto').
Color display is dependent on the terminal's capabilities; older or text-only terminals may not render colors correctly.
TYPICAL USAGE IN SHELL PROFILES
To enable colored ls output permanently, users usually add the following lines to their shell's configuration file (e.g., ~/.bashrc or ~/.zshrc):
eval "$(dircolors)"
And an alias for ls (if not already present):
alias ls='ls --color=auto'
For custom configurations, specify the file:
eval "$(dircolors ~/.my_custom_dircolors)"
CONFIGURATION FILE FORMAT
A dircolors configuration file (like /etc/DIR_COLORS or ~/.dircolors) consists of lines defining colors and attributes for different file types. Each line typically contains a keyword (e.g., DIR for directories, EXE for executables, LINK for symbolic links) followed by a color code (a numerical ANSI escape sequence).
Example entries:
DIR 01;34 (bold blue for directories)
EXE 01;32 (bold green for executables)
.tgz 01;31 (bold red for .tgz files)
It can also specify the terminal type using the TERM keyword.
HISTORY
dircolors is part of the GNU Core Utilities, a fundamental set of tools for Linux and other Unix-like operating systems. Its functionality for configuring ls colors has been a standard feature for many years, providing a robust and flexible way to customize terminal output. It replaced earlier, less standardized methods of achieving colored directory listings, evolving to handle various shell syntaxes and configuration options.