Bringing some colour into your life



Sick of the same old black/white or black/green terminal emulator screen. Linux allows us to set various colours for different type of files - but how does it do this - and how can you change the colours?

I'd liked the feature ever since i first used linux but never really considered how it was working - i did a bit of digging today and found out how it works.

Lets start from the beginning...

ls is not calling ls directly any more - ls is an alias

alias ls='ls $LS_OPTIONS'

and what is in $LS_OPTIONS

echo $LS_OPTIONS
-N --color=tty -T 0


so the clever bit here is that its added the --color option


looking at the man page this tells us that the colouring (not coloring - sorry had to get that in) is dependant on another environment variable LS_COLORS - lets see what's in that

echo $LS_COLORS
no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:

And we get a list of all the mappings that are defined on my system, the first few parameters seem to relate to 'types' of file - i couldn't find a definite mapping for these but there must be a list somewhere - but some of them can be guessed - for instance fi is file and di is directory.

So in my case, files are colour 00 and directories are colour 01;34 - but what are colours 00 and 01;34?

00 just seems to be some default 'grey' colour, 01;34 seems to be bold blue. It seems a combination of 2 attributes is possible 01 seems to mean bold and 34 means blue.

So in your terminal emulator (putty in my case) - everything starts showing up in nice colours.

You can further add your own rules for certain file types, it you want file ending in .doc to show up in yellow you just add that rule to the LS_COLORS variable (*.doc=33 if you are interested)

Having the colour is very useful, i find it very good for just finding directories quickly and seeing which files are executable or not.

Anyway it's useful to know this function is there and a similar thing is applied to vi (well vim) and that also makes editing files easier.

Here is an example below of what things can look like

Here we can see directories are pale orange, zipped files are red executables are green etc

In this case everything was from the system defaults - however directories are defined as  01:34 (bold blue) is very hard to read against a black background.

I wanted to change this and it can be done quite easily as putty allows you to change the definition of the colours inside putty so colour 34 which would normally be blue can be changed to any colour you like - it's still called blue in the system but you can make it orange if you like.....

So in putty my blue is orange - this is changed in the options screen shown below


so red 255, green 128,blue 0 is "orange" - you can see this by clicking modify which shows you what the actual colour looks like.

Changing the setting in putty (while slightly confusing) is easier than changing the di= value in LS_COLORS on every server we have......


2 comments:

  1. vi is slightly easier to modify since you have built in color schemes:
    morning, peachpuff, blue, murphy, ron, zellner, darkblue, desert, koehler, shine etc

    all you need to do is:

    cd ~
    vi .vimrc
    type:
    colorscheme desert
    wq

    try and enjoy :)

    ReplyDelete