5

I recall that eval "dircolors -b" used to display the colours that LS_COLORS was using, based on the file types or extensions. It was not simply the colour values that were displayed but the colours themselves. I could see the colour in which a .png or .ogg file would be displayed and change it if needed through a custom file.

I find that the output of eval "dircolors -b" is no more in colour.

Can someone kindly explain how I might get it back? Perhaps some environment variable is not getting set. Otherwise, is there a workaround?

  • I'm not really understanding how eval "dircolors -b" would ever display the output in color. eval doesn't do any handling on the output of the commands. – EightBitTony Oct 23 '12 at 11:02
  • This is what I recall; I might be wrong. If not that command, then some other similar command allowed me to see the extensions listed in the colours they would display in. That much I remember seeing. The question is what command shows output similar to dircolors but in the respective colours? Sorry for the bother. – chandra Oct 23 '12 at 11:31
  • @Stéphane Gimenez: Your expansion of abbreviations at that weblink is very helpful. I have three abbreviations, rs, ca, and mh that are not included above. Can you please tell me where to find their expansions? Thanks – chandra Oct 26 '12 at 18:25
6

Try this script:

( # Run in a subshell so it won't crash current color settings
    dircolors -b >/dev/null
    IFS=:
    for ls_color in ${LS_COLORS[@]}; do # For all colors
        color=${ls_color##*=}
        ext=${ls_color%%=*}
        echo -en "\E[${color}m${ext}\E[0m " # echo color and extension
    done
    echo
)

Output:

output screenshot

  • Thank you. I remember only the file extensions showing up in their respective colours. I need to do some digging up to understand what IFS is though. – chandra Oct 23 '12 at 18:48
0

This version has some additional information and doesn't color the entire lines:

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       
}

Part of answer by @karthick87 on Askubuntu
Also, see this answer: What causes this green background in 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.