What Are Your Ls_Colors

How do you determine what bash ls colours mean?

The colors are defined by the $LS_COLORS environment variable. Depending on your distro, it is generated automatically when the shell starts, using ~/.dircolors or /etc/DIR_COLORS.

Edit:

To list color meanings, use this script:

eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;"|sed -e 's/:/="/g; s/\;/"\n/g')
{
IFS=:
for i in $LS_COLORS
do
echo -e "\e[${i#*=}m$( x=${i%=*}; [ "${!x}" ] && echo "${!x}" || echo "$x" )\e[m"
done
}

Color code of ls function

I showed a script in How to remove dir background in ls -color output which colorizes the output of dircolors -p (and would be useful in this question, since it preserves the comments which explain what's being colored).

export LS_COLORS : apply the rule for every file beginning by README*

I see several problems here:

You obvously assume that LS_COLOURS already has a value, because you expand it. However, entries in LS_COLOURS are separated by a colon, and you don't have one.

The other problem is that sequence matters: ls parses the entries one after the other, as soon as it finds a matching one, this is the colour it uses. Therefore, more specific entries should be at the start of the colour list.

UPDATE

I tried out various variations with my version of ls(GNU coreutils 8.26) and found that a wildcard pattern such as *README* would be ignored. The only kind of wildcard pattern is an asterisk at the start of the entry. Hence,

LS_COLORS='*README-txt=35;46'  /bin/ls --color=yes *README*

colorizes my file x-README-txt, but

LS_COLORS='*README*=35;46'  /bin/ls --color=yes *README*
LS_COLORS='*READ*-txt=35;46' /bin/ls --color=yes *README*

don't. Also, my above remark about the sequence of entries was not correct. While sequence indeed does matter, entries further to the right take priority. Therefore, if you have

LS_COLORS='*txt=35,46:*t=32,44'  /bin/ls --color=yes *README*

the file x-README-txt would be colorized using 32,44.



Related Topics



Leave a reply



Submit