More colors than ls -G in file extensions

bashterminal

In the output of ls -G, I can see some extensions get colors like symbolic links or .sh files. What if I also want .jpg, .xml, .wav or .log to have different colors too?

Also, is there any way I can set the color extensions list and set separate colors for different extensions?

Best Answer

The colors used by ls -G are based on the file attributes (like directory, symbolic link, executable and so on). See man ls and go to the section on the LSCOLORS environment variable for the list of color values and the order of file attributes to define the colors for each file attribute.

You cannot change the colors by file extension by default. But one way to achieve this is by installing other software, like coreutils, from brew or MacPorts.

Also see this detailed answer on superuser - colouring output of ls according to file extension.