Hello fellow Citrites, Clients and Community Members!

On this Super Bowl Sunday a Client (you know who you are!) asked me quite a wonderful question:

“I can’t stand the command line color for directories in the console: that blue is so hard to see.  Is there a way to change it?”

To the Client (and to all of you), yes – you can change the terminal colors as this is a “Linux thing“.  The colors to identify directories, symbolic links and so forth have been around for as long as I can recall, but I understand the need/want to as what looks like this:

Can look/feel like this… especially if being accessed from certain SSH tools or Virtual Consoles:

Immediately, I felt the fibre channel connections in my skull warming up to re-add Mental Storage Repositories I had long since forgotten.  After a few seconds, I made a note of it as I wanted to share an aesthetic-based “How To” so you can trick out your XenServer command line experience.

1.  The Configuration File

The color definitions for the console are stored in /etc/DIR_COLORS.  From the command line execute the following so you can start tweaking text colors to your liking:

cd ~

cp /etc/DIR_COLORS ~/.dir_colors

What we just did was copy the global color definition file to root’s home directory as .dir_colors, or /root/.dir_colors.  This will allow global color definitions to remain in-tact as well as keep changes for the root user… specific to the root user.

2.  The File Contents

Let us take a look at the file and where you will be looking to make changes: you can edit this file with nano or vi:

nano .dir_colors

or

vi .dir_colors

At the top there is some mumbo-jumbo stuff.  What we are looking for (see below) is in the middle of the .dir_colors file:

 

# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# 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

 

This is the key to changing colors as these commented lines are your “Instruction Manual”!  How so?  Well, there are three aspects to “colors” in the console:

–  Attributes, or styling of text

–  Foreground color

–  Background color

Further along in the file we find the core of terminal color definitions.  These variables are explained in the file and, at a minimum, has to have some kind of attribute applied to it:

NORMAL 00       # global default, although everything should be something.
FILE 00         # normal file
DIR 01;34# directory
LINK 01;36      # symbolic link
FIFO 40;33      # pipe
SOCK 01;35      # socket
BLK 40;33;01    # block device driver
CHR 40;33;01    # character device driver
ORPHAN 01;05;37;41  # orphaned syminks
MISSING 01;05;37;41 # … and the files they point to

# This is for files with execute permission:
EXEC 01;32

3.  Changing Color Attribute, Foreground

SO, I want my directory colors to be visible and easier on the eyes.  I will edit the DIR variable so that the color is… brown!  To do so, I change the line for DIR to:

DIR 01;33       # directory

I save the file and quit the text editor.  To test my colors and see if directories will appear as brown, I type:

exit

This allows me to return back to the command line and from there, I can run:

ls /

… and my directories are NO LONGER DARK BLUE…

Now, I feel like a mad scientist!  If you think you have messed up or forgot what the ORIGINAL value of colors were, you can always re-copy /etc/DIR_COLORS back to root’s home directory by executing:

cd ~

cp /etc/DIR_COLORS ~/.dir_colors

4.  Miscellaneous

The lower portion of the .dir_colors file allows you to specify colors FOR specific file extensions!  Yup… feel like Bob Ross?  I know I do:

Now, this is going a bit crazy… but here is what I changed in my .dir_colors file:

NORMAL 00;34;45 # global default, although everything should be something.
FILE 00;34;45   # normal file
DIR 01;36;45    # directory
LINK 01;36;45   # symbolic link
FIFO 40;33      # pipe
SOCK 01;35      # socket
BLK 40;33;01    # block device driver
CHR 40;33;01    # character device driver
ORPHAN 01;05;37;41  # orphaned syminks
MISSING 01;05;37;41 # … and the files they point to

# This is for files with execute permission:
EXEC 00;37;45

.sh  01;37;45

And this is from my Virtual Desktop to you.

–jkbs

@VerbalJesse