LS_COLORS environmental variable lets you decide on colours for different file types for GNU coreutil's ls command, such as directories, regular files, links etc. I suppose that dot files are considered a variation of the Linux file types and not a type on its own hence there is no option for specifying a display colour for them.

Is there any (other) way you can make ls listings show hidden files in a different colour?

  • This answer has more than you ever wanted to know about LS_COLORS. I couldn't figure out how to get it to work for dotfiles but you might want to check it out.
    – terdon
    Sep 23 '14 at 14:52
  • 1
    @terdon - it doesn't work for dotfiles. It might for some, but very few. There's a limit to an extension's length and most whole filenames will exceed it. It will work for files named *.hide for example. This answer addresses a similar problem for directories, though the answers to this and the directory problem are probably not the same.
    – mikeserv
    Sep 23 '14 at 15:43

If you're only sorting by name, this might help:

alias ll='LS_COLORS=$LS_COLORS:"di=0;34:" ; S_COLORS=$LS_COLORS:"fi=0;37:" ; export LS_COLORS; ls -dHhl --color=auto .*; LS_COLORS=$LS_COLORS:"di=1;94:" ; LS_COLORS=$LS_COLORS:"fi=1;37:" ; export LS_COLORS$

However, it splits the ls command in two parts, one for hidden files and folders, one for the rest.


Yes, use cf. I just released a well-documented version, it specifically colors ls output per file extension and/or certain special attributes (executable, links, hidden and directories). Give it a shot!!! It's hard to let go from using this once you get used to it.



If you just want to highlight hidden files (and folders) and you don't care about the coloring of all the other files, then the obvious approach is to run ls -la | grep -E "^| \.[^/|'.].*"

If you want to maintain the other colors, then things start to get tricky, because $LS_COLORS does not natively support colorizing hidden files as it seems.

I came up with the idea to dynamically append the current directory's hidden files to the $LS_COLORS environment variable as a pseudo extension, then execute ls -la and after that run dircolors to reset the original color schema. Obviously there will be a conflict if a hidden file has the same name as a known extension. Also this method does not work with hidden folders.

Warning: This solution is a (not very thoroughly tested) hack. Use it at your own risk.

for h in $(ls -A | grep "^\."); do LS_COLORS="$LS_COLORS*$h=04;05:"; done; ls -la; eval $(dircolors)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.