In UNIX, many file extensions do not contain the dot in front, as in bashrc rather than bash.rc or ssh_config rather than ssh.config

I would like to add dircolor rules for _config as well. However, when I add the line:

_config 01;31

I get an error: dircolors: `/etc/dircolors':126: unrecognized keyword _config

Is it possible to add extensions _ext to dircolors?

2 Answers 2


You can do this with *_config 01;31.

From man 5 dir_colors:

*extension color-sequence
    Specifies the color used for any file that ends in extension.

.extension color-sequence
    Same as *.extension. Specifies the color used for any file that ends
    in .extension. Note that the period is included in the extension, which
    makes it impossible to specify an extension not starting with a period,
    such as ~ for emacs backup files. This form should be considered obsolete.
  • Thanks, this is great. I don't see any mention of regular expressions or case sensitivity in the man page. Is it possible to use regex ? And do I need to specify all possible permutations of lower upper case .mp3, .MP3, .Mp3, ..., or is there one expression that will match all? Oct 12, 2013 at 9:32
  • 2
    Unforunately it's case sensitive and you can't use regexes. You have to list out all the possible permutations. I checked the source for ls just to make sure there aren't any undocumented features to workaround this, and there aren't. It's just a regular string comparison against the file extension.
    – Matt
    Oct 12, 2013 at 16:39
  • No, there are no undocumented features. BUT someone has already tried hard to work on this issue, see lists.gnu.org/archive/html/bug-coreutils/2012-10/msg00057.html . Unfortunately the author of the patch decided to discard the patch shortly after for various reasons. Mar 23, 2015 at 16:43

As @Matt has corrected me, this is possible using dir_colors. To do this you need to add a line similar to this in one of a few locations.

  • /etc/DIR_COLORS
  • $HOME/.dircolors

excerpt from man page

found in a system default shell initialization file, like /etc/profile or 
/etc/csh.cshrc.  (See  also  dircolors(1).)   Usually, the file used here is 
/etc/DIR_COLORS and can be overridden by a .dir_colors file in one's home 

These files are typically sourced from these files that are patched into your $HOME/.bashrc and $HOME/.bash_profile, assuming you're using Bash as your shell.

$ ls -l /etc/profile.d/|grep colorls
-rw-r--r--. 1 root root 1133 Nov  3  2010 colorls.csh
-rw-r--r--. 1 root root 1143 Nov  3  2010 colorls.sh

If you add your line to say your copy of $HOME/.dircolors:

_config 01;31

You can then update your environment using this command:

$ source /etc/profile.d/colorls.sh

You can then confirm that your environment now includes the change:

$ env|grep -o '*_config=01;31'

Finally you can test to see if your change is working:

$ touch afile_config
ls -l afile_config

              ss of ls output

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.