Add Bling to the ‘ls’ Bash Command with Colorls


colorls usage

Are you a longtime lover of the ls command?

If so here’s a small Ruby gem that, in its own words “beautifies” this common command with color and font-awesome icons.

And the result is as luscious as it is lucid.

Colorls for Bash

Colorls is the name of the script and it (shock!) prettifies the humble ls output with selection of color and icons. When used with other command line customisation options, like Oh my zsh and the powerlevel9k theme you get really slick results:

Now before you scroll down to tell me how utterly trivial this Gem is: that is the point. This is pure eye-candy; a bit of Bash bling; it’s not intended to transform the way you use the terminal.

What it does it tweak the output of the ls command, a useful command for finding out which files are located, and where. The command, which is short for ‘list’, even featured in your list of 5 terminal commands that every Linux user should know.

Using ls on its own, with no flag, will list the names of files and folders within the current directory. This omits information like name file, format, size, date modified, etc. The ls man page shows you what you can do with the command, such as sorting by file size, directory, and so on. Note that most of options won’t work with colorls.

Install Colorls on Ubuntu

Like what you see and want to add Colorls to your system? Great!

You’ll need to install a couple of things to get going, including Ruby and the colorls Ruby Gem, plus a modified font packed full of glyphs.

Step one: Install Ruby (and a few dependencies) from the repos. As you’ll use this via the command line since we’ll install it via the command line too:

sudo apt install ruby ruby-dev ruby-colorize

Step two: Download and install a patched version of your desired terminal font from Nerd Fonts.

Nerd Fonts is project that patches some popular fonts with an impressive amount of of glyphs and emoji. A patched version of Ubuntu Mono (the default terminal font on Ubuntu) is availablem as are a many others, including Roboto and Powerline.

Download a font from Nerd Fonts

Once your chosen font is installed do remember to set it as the terminal font via Terminal > Edit > Profile Preferences > Custom Font.

Step Three: Install the Colorls Ruby gem from the command line using this command:

sudo gem install colorls

Once the Gem is downloaded and built you’ll be ready to start using the colorls command.

However, the developers of Colorls recommend adding a terminal alias for the tool, specifically ‘lc‘, which, if you’re not a Mono developer, shouldn’t conflict with anything else.

You’ll need to modify the .bashrc file(s) and add alias lc='colorls' to do this.

Now when you run ‘lc‘ you’ll see a display of colorful information:

A few useful commands/options to use:

Running lc -r will display a readable ‘report’ on the number of files and folders in the specified folder(s).

Adding --sort-dirs or -sd--sort-files or -sf will sort by directories first, or files first, followed by a list alphabetically.

Using --dirs or -d / --files or -f filters entries to display only directories or files.

Adding -1 will display all entries in a single column.

Powered by WPeMatico

eBay