When you open a Linux terminal and execute ls --color=auto, the file listing appears in distinct colors: bright blue directories, cyan symbolic links, green executables, and red archives. These colors provide immediate visual feedback about file types, permissions, and potential system security risks.

Whether you are inspecting binaries in /usr/bin/, diagnosing a broken link in /etc/, or auditing permission vulnerabilities on a production server, understanding Linux file color codes helps you navigate and troubleshoot Linux environments faster.

Linux File Color Code Reference

Below is the standard color mapping used by GNU ls across major Linux distributions including Ubuntu, Debian, Fedora, and Arch Linux:

  • Bold Blue (`di`): Directory — Standard filesystem folder.

  • Bold Cyan (`ln`): Symbolic Link — Pointer referencing another file or directory path.

  • Bold Green (`ex`): Executable File — Program binary or shell script with execute permissions (chmod +x).

  • Bold Red (`*.tar`, `*.gz`, `*.zip`): Archive / Compressed File — Packed archive or package binary (.deb, .rpm).

  • Bold Magenta (`*.png`, `*.jpg`, `*.mp4`): Image & Media File — Multimedia raster images, vector graphics, or video streams.

  • Yellow with Black Background (`bd`): Block Device — Storage hardware nodes such as /dev/sda or /dev/nvme0n1.

  • Yellow with Red Background (`cd`): Character Device — I/O stream hardware nodes such as /dev/tty or /dev/null.

  • Flashing Red with Black Background (`orphan` / `mi`): Broken Symlink — Symbolic link whose target file has been deleted or moved.

  • White Text with Red Background (`su`): SetUID Binary — Executable that runs with elevated root user privileges (chmod u+s).

  • Black Text with Green/Yellow Background (`tw` / `ow`): World-Writable Directory — Directory like /tmp where any user can write and modify files.

How LS_COLORS and dircolors Control Terminal Output

The ls command relies on the $LS_COLORS environment variable to determine which ANSI color escape codes to apply to each file extension and permission mode. You can inspect your active configuration directly:

Terminal Commandbash
# Inspect current LS_COLORS environment variable
echo $LS_COLORS
 
# Sample Output String:
# rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.zip=01;31:*.png=01;35:

Customizing LS_COLORS for Your Terminal Theme

To customize file listing colors (such as matching Solarized, Catppuccin, or Gruvbox terminal color schemes), generate a custom .dircolors configuration file using the built-in dircolors tool:

dircolors Setup Commandsbash
# 1. Export default dircolors configuration template to your home directory
dircolors -p > ~/.dircolors
 
# 2. Edit ~/.dircolors to update color definitions
nano ~/.dircolors
 
# Example edits inside ~/.dircolors:
# DIR 01;34      # Directory: Bold Blue (01=Bold, 34=Blue)
# EXEC 01;32     # Executable: Bold Green (01=Bold, 32=Green)
# .py 01;33      # Custom Python file rule: Bold Yellow
 
# 3. Add dircolors initialization to your shell profile (~/.bashrc or ~/.zshrc)
echo 'eval "$(dircolors -b ~/.dircolors)"' >> ~/.bashrc
source ~/.bashrc

ANSI Escape Sequence Syntax Breakdown

Color codes in LS_COLORS follow the standard ANSI format Attribute;Foreground;Background:

  • Attributes: 00 (Normal), 01 (Bold), 04 (Underline), 05 (Blink).

  • Foreground Colors: 30 (Black), 31 (Red), 32 (Green), 33 (Yellow), 34 (Blue), 35 (Magenta), 36 (Cyan), 37 (White).

  • Background Colors: 40 (Black), 41 (Red), 42 (Green), 43 (Yellow), 44 (Blue), 45 (Magenta), 46 (Cyan), 47 (White).

Security Auditing: Identifying High-Risk File Colors

Terminal file colors provide immediate visual security flags during system administration:

Troubleshooting Terminal Display Issues

  • `ls` displays plain monochrome text: Ensure ls is aliased to ls --color=auto. Add alias ls="ls --color=auto" to ~/.bashrc.

  • `TERM` variable unconfigured: Run echo $TERM to verify it is set to xterm-256color or screen-256color. If set to dumb, color output is disabled.

  • Unreadable text on dark or light backgrounds: Customize DIR and LINK rules in ~/.dircolors to maintain high contrast.