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
Siege Aborted Due to Excessive Socket Failure
Get Latest Release Version Number for Chrome Browser
Kafka Console Consumer with Kerberos Authentication
Why Use G++ Instead of Gcc to Compile *.Cc Files
Linux: Send Mail After a Process Id Finishes or Is Killed
Runner Is Not Healthy and Will Be Disabled
How to Simulate Two Consecutive Enter Key Presses for a Command in a Bash Script
Write Current Date/Time to a File Using Shell Script
How to List All Binary File Extensions Within a Directory Tree
Under What Circumstances Does The Read() Syscall Return 0
Adjust Audio Volume Level with Cli Omxplayer - Raspberry Pi
Linux: How to Debug a Sigsegv? How to Trace The Error Source
Linux: Checking If a Socket/Pipe Is Broken Without Doing a Read()/Write()
Self Updating Bash Script from Github
Docker Container Can Reach Dns But Not Resolve Hosts
Using a Chef Recipe to Append Multiple Lines to a Config File