About Archive Other Contact

How to get colors with ls on FreeBSD

FreeBSD uses the csh as standard shell for the user accounts. One of the most used commands in your shell is ls. This post shows how to get some colors with gnuls in this shell.


The following requirements have to be in place to be able to implement what is described in this post:

ls results in color

One of the most used commands in your shell is ls. The standard ls command supports color. But here at SoCruel.NU gnuls is used.

To install gnuls run:

# pkg install gnuls

Then we have to make sure that we use gnuls by adding an alias to the users .cshrc file, which resides in the users homedirectory:

alias ls        gnuls -a --color

Now we have to take care of 2 more items.

First we define the colors we want to use in our gnuls output. We do this with the .dircolors file, which is located in the root of our home directory. The .dircolors file used at SoCruel.NU looks like this.

Second we make sure we use this .dircolors file by adding the following lines to the users .cshrc file (in the if ($?prompt) then section):

eval dircolors -c ~/.dir_colors
set LS_OPTIONS = '-F -s -T 0 --color=tty'

If we have this in place we can reload our new .cshrc file to use our new colors:

$ cd ~
$ source .cshrc


Some (other) resources about this subject:

Updated: August 21, 2018