4

Problem: I am trying to modify LS_COLORS to gray out all files ending with the tilde character.

Question: Can anybody spot my mistake?

Here is what I did:

# write dircolors file:
dircolors -p > ~/.dircolors

# add a line
echo >> ~/.dircolors
echo ".*~ 01;34" >> ~/.dircolors

# apply changes to LS_COLOR
eval "$(dircolors -b ~/.dircolors)"

Now, when I do

echo $LS_COLORS

I get a long line with the following begin and end:

rs=0:di=01;34:ln=01;36: ... *.xspf=00;36:*.*~=01;34:

So I would assume, that files ending with tilde (~) appear in the same color as directories (specified by di), but it doesn't work.

flonk
  • 215
  • 2
  • 7

1 Answers1

4

It seems you can't do this with dircolors, but you can do it by modifying LS_COLORS directly:

eval "$(dircolors)"
LS_COLORS="${LS_COLORS}*~=01;34:"
export LS_COLORS

dircolors only seems to handle three types of descriptors: terminal names (starting with TERM), file types (e.g. DIR), and extensions starting with .. The latter get expanded by prefixing them with *; so your .*~ becomes *.*~, which only matches backup files containing a .. ls itself can interpret more general LS_COLORS entries such as *~, which matches all files ending with ~.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164