Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to set regex patterns for color matching in the LS_COLORS variable? So instead of just


Can I do


That's just an example, I'd like to get more complicated than that. Am I asking too much from this? Is there another way to do terminal color schemes that I can get fancier?

I'm using zsh btw, so if I can do it there but not bash, that's fine.

share|improve this question

That's a feature of the ls utility in GNU coreutils. It doesn't depend on the shell. The syntax is not documented (you're supposed to use dircolors and figure it from there), but a quick look at the source shows that the only way to match files by name is to use * followed by a string which must be a suffix for a file name to match. The string is interpreted literally, except that \ and ^ introduce escape sequences (e.g. \n = ^J = newline).

So you can't match different extensions with the same pattern. But you can use shell programming constructs to build LS_COLORS:

for ext in jpg gif; do LS_COLORS="$LS_COLORS:*.$ext=38;5;220"; done
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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