Understanding the Color Code of Linux Files

You may know that everything is a file on Linux, including a hard disk, graphics card, USB, etc.

Linux uses color code to distinguish file types.

As a Linux administrator you don’t have to memorize all kinds of color code, but you do need to remember some color codes that you use on a daily basis.

Typically, you will see different colors for the directory, link file and archive file.

When using the ls command on your terminal you will find some files with color.

The ls command uses the environment variable “LS_COLORS” to determine the colors in which the filenames are to be displayed.

You can see the list of file types and their color code by calling the LS_COLORS variable. You may not understand anything when you first see this output, but we will explain it in detail here.

# echo $LS_COLORS
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:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:

The default color code configuration file is located in /etc/DIR_COLORS.

# cat /etc/DIR_COLORS

It uses three types of color codes for files.

  • File attribute codes
  • Text color codes
  • Background color codes

There are many color codes, but you can often find only the below 7 colors.

  • White (No color code) Regular File or Normal File
  • Blue Directory
  • Bright Green: Executable File
  • Bright Red: Archive file or Compressed File
  • Magenta Image File
  • Cyan Audio File
  • Sky Blue Symbolic Link File

List of File Type Codes

Here is the list of file type codes.

+--------------+--------------------+
|    Code      |      File Types    |
+--------------+--------------------+
|      di      | Directory          |
|      fi      | File               |
|      ex      | Executable File    |
|      ln      | Symbolic Link      |
|      pi      | Named Pipe (FIFO)  |
|      so      | Socket             |
|      bd      | Block Device       |
|      cd      | Character Device   |
|      mi      | Missing File       |
|  *.extension | Example: *.mp3     |
+--------------+--------------------+

List of Text code Attributes

Here is the list of text code attributes.

+--------------+--------------------+
|    Code      |      Attributes    |
+--------------+--------------------+
|      00      | None               |
|      01      | Bold               |
|      04      | Underscore         |
|      05      | Blink              |
|      07      | Reverse            |
|      08      | Concealed          |
+--------------+--------------------+

List of Text color codes

Here is the list of Text color codes.

+--------------+--------------------+     +--------------+--------------------+ 
|    Code      |      Text Color    |     |    Code      |      Text Color    |
+--------------+--------------------+     +--------------+--------------------+
|      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              |
+--------------+--------------------+     +--------------+--------------------+

List of Background color codes

Here is the list of Background color codes.

+--------------+--------------------+     +--------------+--------------------+ 
|    Code      | Background Color   |     |    Code      | Background Color   |
+--------------+--------------------+     +--------------+--------------------+ 
|      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              |
+--------------+--------------------+     +--------------+--------------------+ 

How to Set Custom Color for Files on Linux

You can change the default color code of Linux files if you want to try a different color instead.

To do so, follow the below procedure. The default folder color is “Blue” but we are going to change this to “Yellow” with “Underline”.

If so, the combination should be di=4;33.

# LS_COLORS="di=4;33"
# ls

If you want to make it permanent, use the following steps.

$ echo "LS_COLORS="di=4;33"" >> ~/.bashrc

Finally, run the below command to make them permanent.

$ source ~/.bashrc

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...