SoCruel.NU

The domain that loves BSD

Home About Me Archive 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.

Requirements

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

  • an up to date FreeBSD version 10.x or 11.x
  • a connection to the internet with access to a public caching name server or
  • a connection to a local caching name server which has access to a public root or caching name server

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

Resources

Some (other) resources about this subject:

Updated: August 21, 2018