Master Linux File Color Codes: Customize LS_COLORS for Clearer Directory Listings
This guide explains how Linux uses the LS_COLORS environment variable to assign distinct colors to file types in terminal listings, shows where the default definitions reside, details attribute, text, and background codes, and provides step‑by‑step instructions for creating custom color schemes via your bash configuration.
Overview
Linux terminals display file names in different colors based on their type, using the LS_COLORS environment variable. The colors help users quickly distinguish directories, symbolic links, executables, and other file categories when running the ls command.
Viewing the Current Color Scheme
You can view the current color definitions by echoing the variable: echo $LS_COLORS The output is a colon‑separated list where each entry maps a file‑type code to a set of attribute and color numbers, for example di=01;34 (directories in bold blue).
Default Configuration File
The system‑wide defaults are stored in /etc/DIR_COLORS. This file contains the same colon‑separated format and serves as the base for user customizations.
Types of Color Codes
Three categories of codes are used:
Attribute codes : range 00‑08 (e.g., 01 for bold, 04 for underline).
Text color codes : range 30‑37 and 90‑97 (e.g., 31 for red, 92 for light green).
Background color codes : range 40‑47 and 100‑107 (e.g., 44 for blue background, 106 for light turquoise).
Common File‑type Codes
di– directory fi – regular file ex – executable ln – symbolic link so – socket bd – block device cd – character device mi – missing file *.extension – pattern for specific extensions (e.g., *.mp3, *.jpeg)
Attribute Codes
00 – None
01 – Bold
04 – Underscore
05 – Blink
07 – Reverse
08 – Concealed
Text Color Codes
30 – Black 90 – Dark grey
31 – Red 91 – Light red
32 – Green 92 – Light green
33 – Yellow 93 – Yellow
34 – Blue 94 – Light blue
35 – Magenta 95 – Light purple
36 – Cyan 96 – Turquoise
37 – White 97 – White
Background Color Codes
40 – Black 100 – Dark grey
41 – Red 101 – Light red
42 – Green 102 – Light green
43 – Yellow 103 – Yellow
44 – Blue 104 – Light blue
45 – Magenta 105 – Light purple
46 – Cyan 106 – Turquoise
47 – White 107 – White
Customizing Colors
To change a specific file‑type color, assign a new LS_COLORS string. For example, to make directories appear with an underline (code 04) and a light yellow foreground (code 93), use: LS_COLORS="di=4;93" Add this line to your ~/.bashrc (or another shell startup file) and reload the configuration:
echo "LS_COLORS=\"di=4;93\"" >> ~/.bashrc
source ~/.bashrcAfter reloading, directory entries will be underlined and displayed in light yellow, confirming that the custom scheme is active.
Conclusion
The LS_COLORS variable provides granular control over how file types are colored in the Linux terminal. By understanding attribute, text, and background codes and editing ~/.bashrc, users can create personalized, high‑contrast listings that improve readability and workflow efficiency.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
