Skip to content
Advertisement

Colour code files based on extension in linux

I was wondering if in linux there were a way to coulor files by extension, so that, for example a .py or a .C file would have a different color.

So far, all I managed to do is to change the colouring scheme in the ~/.bashrc file to distinguish directories, executables etc. but no way to colour code the files based on the extension.

Thanks in advance.

Advertisement

Answer

The ls command uses the environment variable LS_COLORS to determine the colors in which the filenames are to be displayed. This environment variable is usually set by a command like

eval `dircolors some_path/dir_colors`

found in a system default shell initialization file, like /etc/profile or /etc/csh.cshrc. Usually, the file used here is /etc/DIR_COLORS and can be overridden by a .dir_colors file in one’s home directory.

You can find more information by typing in the terminal man dir_colors

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement