Home » Linux Host, Ubuntu, SysAdmin » Understanding the Color Code of Linux Files

Understanding the Color Code of Linux Files

In Linux everything present is considered as a file, so to differentiate file types from each other for better visibility to user, Linux has specific color codes for the different file types.

Below, we will try to create some of the files and know its colors.

 $ mkdir linux-color-coding 

White Color – Indicates regular files. so it can be text file, word document or pdf document etc. Lets create simple text file as,

$ echo "hello text file" > textfile.txt

All the normal files created / present, by default has the permission set to “664”

$ ls -alh
-rw-rw-r-- 1 myuser myuser   16 Aug 23 07:43 textfile.txt

Bright Green – Indicates file which are executable. All the executable files in Linux has “x” i.e. executable permissions set, which makes the permissions as “775”
Lets create one simple C program and compile it to generate executable as,

 $ vim helloworld.c 
#include <stdio.h>
int main(int argc, char **argv) {
        printf("hello world\n");
        return 0;
}


Compile to generate executable file as,

 $ gcc -o helloworld_exe helloworld.c 

We can check the default permissions set by above compilation for executable “helloworld_exe” is “775” as,

$ ls -alh
-rw-rw-r-- 1 myuser myuser   92 Aug 23 07:52 helloworld.c
-rwxrwxr-x 1 myuser myuser 7.2K Aug 23 07:52 helloworld_exe

Blue – Indicates its a directory. Default permissions of the newly created directory is 775

 $ mkdir directory_name 
$ ls -alh
drwxrwxr-x 2 myuser myuser 4.0K Aug 23 09:36 directory_name

Yellow – Indicates its a device file. Most of the device files created by Linux kernel resides in /dev . Below is an example of device file which will be displayed in yellow color.

$ ls -al /dev/console 
crw------- 1 root root 5, 1 Aug 23 09:25 /dev/console 

Cyan / greenish-blue – Indicates its a softlink to another file. We can create a softlink to our previously created executable as,

 $ ln -sf helloworld_exe helloworld_softlink 
 $ ls -alh 

-rwxrwxr-x 1 myuser myuser 7.2K Aug 23 09:59 helloworld_exe
lrwxrwxrwx 1 myuser myuser 14 Aug 23 10:00 helloworld_softlink -> helloworld_exe

Red with light black background – Indicates its a broken softlink. Means, the file where the link was pointing has been deleted.
We will try to create a broken softlink as,

 $ gcc -o helloworld_exe1 helloworld.c
$ ln -sf helloworld_exe1 helloworld_softlink_broken
$ rm -rf helloworld_exe1
$ ls -alh
lrwxrwxrwx 1 myuser myuser   15 Aug 23 10:05 helloworld_softlink_broken -> helloworld_exe1

Here, helloworld_exe1 we purposefully deleted to create broken softlink.

Magneta ( a light mauvish-crimson color ) Indicates it is a “Image” or “Video” file depending on the extension of file.

$ ls -alh
-rw-rw-r-- 1 myuser myuser  93K Aug 23 10:11 mypicture.jpg 


Red – Indicates its archive / compressed file.

We will create a simple zip with the existing files as,

$ zip -r hello.zip helloworld.c helloworld_exe 
  adding: helloworld.c (deflated 3%)
  adding: helloworld_exe (deflated 68%) 

$ ls -alh
-rw-rw-r-- 1 myuser myuser 2.8K Aug 23 10:18 hello.zip
-rw-rw-r-- 1 myuser myuser  93K Aug 23 10:11 mypicture.jpg

$ file hello.zip 
hello.zip: Zip archive data, at least v2.0 to extract

So finally this will Look Like below,


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment