Understanding the Color Code of Linux files

Everything in Linux is considered a file (including a hard disk, graphics card, USB, etc,.). Hence, Linux has specific color codes for different file types to distinguish them from each other for better viewing by the user.

As a Linux administrator you don’t have to memorize all the color code’s, 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.

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 respective color codes 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

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 will often see only the 7 colors listed below:

  • 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

List of file type codes and symbols are listed below. The “ls” command will help you identify and categorize the seven different file types found on a Linux system. File type symbols appear as the first character of the file permission part, which is used to identify the file type.

CodesymbolFile Types
exExecutable File
lnlSymbolic Link File
pipNamed Pipe (FIFO)
bdbBlock Device
cdcCharacter Device
mi Missing File
*.extensionExample: *.mp3, *.png, etc,.

List of text code attributes

Here is the list of text code attributes.


List of text & background color codes

Here is the list of Text color codes:

ColorForeground Code (Text)Background Code
dark grey90100
light red91101
light green92102
light yellow93103
light blue94104
light purple95105
light white97107

How to set custom Color for files in 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 that to “Yellow” with “Underline”.

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

# LS_COLORS="di=4;33"

# ls -lh

If you want to make it permanent, just append the value into the “.bashrc” file :

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

Finally, run the below command for the changes to take effect:

$ source ~/.bashrc

Changing the text color

By default any command output displays in “White” color on the terminal as well as in the shell script. You can change the text color of the command output as per your choice by using the color code. For instance, I will be printing the following text with “Green” color.

$ echo $'\e[1;32m'Welcome to 2DayGeek$'\e[0m'

Alternatively, you can use a number of commands for this purpose such as “lolcat”, “tput” and “highlight”. However, we will use “tput” as it comes pre-installed as part of core utility.

Print the following text in “Red” color, print only the “White” background for the last part of the text, using the following command.

$ echo "$(tput setaf 1)$(tput bold)Welcome to $(tput setab 7)2DayGeek$(tput sgr 0)"

Closing Notes

This article explained how to use color codes for files & directories in Linux.

If you found this article helpful, please do share with your friends and spread the knowledge. Please feel free to comment below if you have any queries/concerns. We will get back to you as soon as we can. Happy learning!

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *