ls --color and dircolors

Archived topics about LMDE 1
Locked
phekdra
Level 1
Level 1
Posts: 1
Joined: Sat Apr 30, 2011 2:49 am

ls --color and dircolors

Post by phekdra » Sat May 07, 2011 3:07 am

Hello all, I've just switched from Ubuntu and I'm having a bit of difficulty getting ls to colour different types of files. From nosing through /etc/bash.bashrc it looks as though if I don't have a DIR_COLORS file (which I don't), the dircolors command should be used to set the required LS_COLORS environment variable, however this isn't working (I have set use_color=true). In fact, when I use dircolors directly from the command line:

dircolors -b

I get:

Code: Select all

LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:';
export LS_COLORS
If I then do an export LS_COLORS=<blah> it works, but seemingly not from the bashrc file. Alias shows that ls --color=auto is set.

On a different note well done to all the Mint developers - I'm greatly enjoying the Mint experience and having a bit more manual control again, although as you can tell my shell scripting could do with some work! Ubuntu was starting to get a bit too slick and greasy for my liking. :D

A

User avatar
hunkirdowne
Level 1
Level 1
Posts: 33
Joined: Sat Nov 14, 2009 8:18 am

Re: ls --color and dircolors

Post by hunkirdowne » Sun Jun 05, 2011 7:18 pm

Can someone point me in the right direction to turn the correct colors on for broken symlinks?

I am having a similar (or the same) issue.

An excerpt from

Code: Select all

dircolors -p
shows
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file
.jpg 01;35


So LINK should be bold cyan (and it is), but ORPHAN should be red (but is not). Furthermore, .jpg should be bold magenta, which it is not, so something is broke somewhere.

Another possibility is that xterm colors are set in some config file that I am not (yet) aware of.

Any ideas?
--
\___...---^---...___/
_\-------------------/

dru8274
Level 1
Level 1
Posts: 2
Joined: Mon Aug 08, 2011 6:10 pm

Re: ls --color and dircolors

Post by dru8274 » Mon Aug 29, 2011 3:28 am

I too am newish to Mint LMDE, and am looking closely at my config files. And for whatever, dircolors wasn't working properly for me either. Anyway, I now invoke ~/.dircolors in my bashrc, and have modified it to please myself. And I have found a very nice large .dircolors file at https://github.com/trapd00r/LS_COLORS/b ... /LS_COLORS Hope that's useful.

mangue
Level 1
Level 1
Posts: 2
Joined: Thu Sep 29, 2011 5:25 pm

Re: ls --color and dircolors

Post by mangue » Thu Sep 29, 2011 5:34 pm

Yep It's Broken. Used to work and broke at at the same time mint-fortune broke as well.

Taking a look at /etc/bash.bashrc you can see a variable use_color that is used in various conditions in the script. Even setting it to true the colors are imcomplete. For exemple, mp3 and compressed files aren't shown with colors.

The mint-fortune problem is because the script is using the /desktop directory that only exists in the livecd. It can be fixed by editing the file /usr/bin/mint-fortune and calling the show_fortune funcion in the last line.

Or just do this:

Code: Select all

sudo -i
echo show_fortune >> /usr/bin/mint/fortune
Would be nice to hear from devs about the color problem.

mangue
Level 1
Level 1
Posts: 2
Joined: Thu Sep 29, 2011 5:25 pm

Re: ls --color and dircolors

Post by mangue » Thu Sep 29, 2011 6:12 pm

Ok I figured it out. The problem is in the /etc/bash.bashrc file indeed.

There are two problems in this file. You will need to edit it with your favorite editor. I'll use vim.

Code: Select all

sudo vi /etc/bash.bashrc
The variable use_color is set to false. Set it to true (default is line 18).

Code: Select all

use_color=true
If you scroll a little bit more (line 34 in my file) you see an "if" condition using the variable we just set to true. There's two things that must be met to use colors. One is the existence of the .dir_colors inside your home directory (which I haven't) and the second is the existence of /etc/DIR_COLOR, which is also false in a default LMDE installation.
To fix this, have an "else" in the end of this code block. Only to lines are needed.

Code: Select all

 if ${use_color} ; then
        # Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
        if type -P dircolors >/dev/null ; then
                if [[ -f ~/.dir_colors ]] ; then
                        eval $(dircolors -b ~/.dir_colors)
                elif [[ -f /etc/DIR_COLORS ]] ; then
                        eval $(dircolors -b /etc/DIR_COLORS)
                else # I ADDED THIS LINE!
                        eval "$(dircolors -b)" # I ADDED THIS AS WELL!
                fi
It will fix colors for every user. I also don't know why some colors where showing before this procedure.

Iota
Level 1
Level 1
Posts: 1
Joined: Tue Oct 01, 2013 3:08 pm

Re: ls --color and dircolors

Post by Iota » Tue Oct 01, 2013 3:13 pm

I may be wrong, but ln may have been changed, I don't think making hard links were always default. And hard links are 00 or your default color for everything that doesn't have a color.

Locked

Return to “LMDE 1 Archive”