Charly’s Column – colorls

Color Cast

Article from Issue 211/2018

The first time in our lives we got to a black-and-white Linux or Unix shell, most of us probably typed ls first. In a mixture of nostalgia and the knowledge that life is colorful, columnist Charly Kühnast plays a colorful trump card with colorls.

colorls [1] is written in Ruby. If you don't have this language on your system yet, install it quickly:

sudo apt install ruby ruby-dev ruby-colorize

Then you download a character set that you really like from Nerd Fonts [2] – say, Roboto Mono Nerd Font Regular. After unpacking the ZIP file, I moved the character set to the /usr/share/fonts/truetype/roboto/ directory on my Ubuntu desktop; users of other distributions may need to change this path.

Why do I even get this font when there are a few dozen others preinstalled? Because Nerd Font's character sets are more extensive, containing more symbols, special characters, glyphs, and emojis than usual (Figure 1). Now I select the new font in my terminal's preferences. This fulfills the preconditions, and I can proceed to install colorls by typing:

sudo gem install colorls
Figure 1: On Nerd Font's Cheat Sheet [3], you can see the extended character sets.

The developers know that nobody types colorls 50 times a day. I recommend that you create an lc alias in your ~/.bashrc:

alias lc='colorls'

If you use a light terminal background, you should always specify --light or, preferably, make it permanent by appending it to the .bashrc alias. The output then resembles that in Figure 2 – note the cute icons and bright colors. Light-shy workers can choose a variant optimized for dark terminals by specifying --dark.

Figure 2: colorls --light prints files and directories in a light color scheme.

No Blind Faith in Color

Speaking of the downside: colorls is a new implementation of ls, which does not implement all options identically and others not at all. My big favorites -l and --sort=size fortunately work. If you type -f, colorls only displays files; -d only displays directories. If I want to see both, I have the choice between --sd (directories first – note the two dashes!) and --sf (files first).

If you would like a brightly colored ls, but have problems with colorls because of missing parameters, schedule a test run with exa [4], which doesn't offer any fancy icons but does support almost all the ls parameters and adds some on top. Especially with the defaults, exa impresses – for example, the -h parameter (human readable), which outputs file sizes in human-readable units instead of bytes, is implicit.

The Author

Charly Kühnast manages Unix systems in the data center in the Lower Rhine region of Germany. His responsibilities include ensuring the security and availability of firewalls and the DMZ.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Colorful lsd

    A revamp of ls, lsd offers color coding plus revised options relevant to the modern computer.

  • Charly’s Column: Cluster SSH

    Charly doesn’t relish the idea of searching through the logfiles of a dozen proxy servers when page requests fail. Now that he has deployed Cluster SSH, he can pull the strings on many machines at the same time.

  • The sys admin's daily grind: Smorgasbord

    Sys admin columnist Charly Kühnast has an electronic note box in which he collects ideas and small snippets of code. He calls it his "quarry" and is taking this opportunity to offer up some collectors' items to regular readers.

  • Vim Primping

    Working with the infamous Vim is part of every sys admin's daily work. Charly spices up the veteran editor with personal settings for syntax highlighting and indentations.

  • Show Me!

    There is nothing that admins hate more than unnecessary typing at the console. That's why Charly's clever alternative exa replaces the classic, but ancient, ls.

comments powered by Disqus