3

when using ls the directories are in a really hard to read navy blue, so I want to change them.

I read that I need to set LS_COLORS but for me it doesn't do anything.

Here's what I tried: LS_COLORS="dir=0;35" and then ls --color=auto but the directories are still navy.

Also when I'm opening a new session LS_COLORS has no value, ls still print in color though.

Is there another variable I have to set? And how can I change the colors?

edit: I did not export the variable. Which made it impossible for ls to read its content

3 Answers 3

1

You need to export the variables too. If a variable is not exported then any new child processes won't be able to see them.

Just add export before the variable declaration like so, export LS_COLORS="di=0;35".

However all variables will be erased after each session, and will need to be set again at the start of every new session. To do this automatically (assuming you are using bash) just add the line to the file ~/.bashrc as this file is run every time a new bash session is started.

5
  • Looks like its doing something. Now I get unparsable value for LS_COLORS
    – iaquobe
    Commented Oct 6, 2019 at 19:05
  • It's because dir isn't a valid file type. If you want to colour directories it should be di=0;35 instead.
    – Christer
    Commented Oct 6, 2019 at 19:11
  • 1
    Ok, I figured it out. Its supposed to be "di=..." not "dir=...". Thanks alot :) (oh, you were faster than me)
    – iaquobe
    Commented Oct 6, 2019 at 19:13
  • I thought about it and I'm still wondering why LS_COLORS was empty but lsstill printed in color. Does it just take default values if nothing is specified?
    – iaquobe
    Commented Oct 7, 2019 at 11:27
  • My best guess is that ls has built-in default values (for directories, symbolic links, etc.) and any colour definitions in LS_COLORS simply adds to or overwrites those values.
    – Christer
    Commented Oct 7, 2019 at 15:04
1

You can also quite easily change that navy blue into any kind of blue with setvtrgb. The --help option explains:

FILE should be exactly 3 lines of comma-separated decimal values for RED, GREEN, and BLUE.

To seed a valid FILE: cat /sys/module/vt/parameters/default_{red,grn,blu} > FILE

and then edit the values in FILE.

Here is what that three-line-file can look like:

000,  250,120,200, 64,190, 50,  170,85,  240, 85,220, 80,232, 55,  220
000,  100,186,140,128,120,190,  170,85,   60,211,210,150, 85,222,  220
000,   40,120, 20,200,190,160,  170,85,   30, 85, 80,255,212,222,  220

You can not have comments, but whitespace is OK. It helps!

You read the RGB values top to bottom. The 16 colors run from left to right.

Blue is (64,128,200). Bold blue is (80,150,255). Original Navy blue was something like (0,0,225). I just added green and a bit red.

And here is how I define (and export!) LS_COLORS. (dircolors -p to look up the codes.).

LS_COLORS="fi=01;37:di=01;34:ex=01;32:ln=37\
:or=01;30:mi=00:mh=31\
:pi=33:so=43;30:do=35\
:bd=35;01:cd=35\
:su=37;41:sg=30;43:ca=30;41\
:tw=07;34:ow=30;44:st=30;44"

export LS_COLORS

# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
0

You can print the defaults with the dircolor -p command, change the current color for directories (DIR 01;34 = blue) with sed and use this output as input for the dircolors command.

This prints the modified value for the LS_COLORS variable and the export LS_COLORS command:

dircolors <(dircolors -p | sed 's/DIR 01;34/DIR 01;35/')

If you're using bash, you could append this output to your ~/.bashrc and source the modified ~/.bashrc:

dircolors <(dircolors -p | sed 's/DIR 01;34/DIR 01;35/') >> ~/.bashrc
. ~/.bashrc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .