This is your command line on lsd

Command Line – lsd

© Lead Image © bluedarkat, 123RF.com

© Lead Image © bluedarkat, 123RF.com

Article from Issue 252/2021
Author(s):

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

If you work at the command line, you probably use ls [1] frequently to list directories and their contents. However, it is one of the oldest commands, and many of its options are no longer relevant to modern computer use. In fact, most people can get by with only a small sub-set of its available options. One of several new revamps, lsd (LSDeluxe) [2] (Figure 1) attempts to modernize and simplify ls by assuming a default color code and – apparently – by reducing the number of options and adding options of its own. However, since this is 0.2.21 release, it is hard to be sure exactly what the general release will look like.

Figure 1: One of the leading updates to ls, lsd attempts to modernize and simplify the command.

The lsd release page includes Linux packages for Debian and Gentoo. An alternative is to build from source with the Rust Cargo package manager or install a Snap package. Should you install from source, you will also need to install Nerd Fonts [3] in order to use fancy icons to identify file types.

On installation – or perhaps later, after you have tried lsd and have a better sense of what it can do – you may also want to add a configuration file (Figure 2), copying and modifying the sample provided on the project page. This configuration file should be placed in ~/.config/lsd/config.yaml. Table 1 lists the main fields available and their settings. Default configurations can be overridden from the command line but can reduce the length of entered commands.

Table 1

Selected Configuration Settings

Field

Description

Values

Default

classic

Sets backward compatibility with ls

false, true

false

blocks

Specifies the columns and their order

permission, user, group, size, size_value, date, name, inode

permission, user, group, size, date

color

When to colorize

never, auto, always

auto (never when classic is set to true)

date

Date format for date column

date, relative, '+date_format' (a strftime formatted value, i.e., '%d %b %y %X')

date

dereference

Whether to dereference symbolic links

false, true

false

display

What items to display

all, almost-all, directory-only

all

icons:when

When to use icons

always, auto, never

auto (never when set to classic)

icons:theme

Which icon theme to use

fancy, unicode

fancy (unicode if Nerd Fonts not installed)

icons:separator

How the icon is separated from the file name

' '

Single space

layout

Which layout to use

grid, tree, oneline

grid

recursion:enabled

Whether to enable recursion

false, true

false

recursion:depth

The recursion depth

Any positive number

3

size

The format of the size column

default, short, bytes

default

sorting:column

Specify what to sort by

extension, name, time, size, version

name

sorting:reverse

Whether to reverse the sorting

false, true

false

sorting:dir-grouping

Whether to group directories and where

first, last, none

none

Figure 2: Use a configuration file to customize lsd.

Note that in the current release the set colors cannot be altered, although that may change in later releases. Figure 3 shows the default colors currently in use. Colors are only the most obvious ways that directories and files can be coded, the others being --icons and --icon-themes (Figure 4) and --classify (-F), which uses special characters (*, /, =, >, @, and |) to indicate file types. Probably, most users will want to use only one of these choices.

Figure 3: lsd uses a complex color code for files.
Figure 4: A close-up of the fancy icons that lsd can use.

Options

The current ls command has 58 options. By contrast, the current lsd release has 25. More might be added before the general release, but lsd is already a functional match for ls and broadly backwardly compatible with it, with much of the same structural logic. However, some of the ls options are less relevant than they once were. For instance, today only a few applications like Bluefish use ~ to indicate a backup file, so the ls option --ignore-backups (-B) is unlikely to be missed. Similarly, the decline of Emac's popularity means that the --dired (-D) option to generate output for Emac's Dired mode seems no longer necessary or at least a low priority to implement. Nor does lsd require the -C option for displaying in columns – because it does so by default and other options such as tree or single-line displays are folded into the same command. The overall result is that lsd is easier to learn than ls, especially when more than basic options are used.

So what options are left? First, the options that can be placed in a configuration file (Figure 2). They take the same possible values as in the configuration file and override the file as well. Another set of options are those found in ls. In particular, --all (-a) displays dot files, and --nosymlink does not display symbolic links, while -directly-only (-d) lists only directories. The same sorting options are also used: --recursive (-r), --reverse (-r), --sizesort (-s), and --timesort (-t), all of which are self-explanatory. Other options include --total-size, which displays the total size of directories, and --oneline (-1) and --tree, which offer alternative displays (Figure 5 and 6). And if you have no wish for color or icon coding, you can use --classic to suppress them. If you are proficient with ls, many of these options will be familiar.

Figure 5: An alternative to lsd's column display is to display file names, one per line.
Figure 6: A tree structure is also an option in lsd.

Naturally, which options you require depends on your current tasks, but you are likely to develop preferences in layout. When you do, consider creating an alias for lsd so that you have no need to break the habit of typing ls. To give the simplest alias, in your ~/.bashrc file or its equivalent, add the line:

<C>alias ls='lsd'<C>

You may want to set other aliases for lsd, each with its own set of options.

Other ls Updates

In addition to lsd, at least five more revisions of ls are competing for the same niche: exa, colorls, ls++, ls-go, and k. Many of these are released under an MIT license, and most focus on a color display. However, lsd is an ideal place to begin exploring the new alternatives. Backwards compatibility makes it an obvious replacement for ls. While various forms of file coding may be too complex for some users, lsd offers several choices. However, if lsd is not for you, you have others to fall back on. Obviously, the time has come to revamp one of Linux's most basic commands.

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest coast art (http://brucebyfield.wordpress.com). He is also co-founder of Prentice Pieces, a blog about writing and fantasy at https://prenticepieces.com/.

Buy this article as PDF

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

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line: tree

    The tree command can provide a clear view of all your files and directories and offers a few advantages over the usual ls command.

  • File Comparison

    With support for more than 60 file formats, diffoscope extends the power of diff beyond the plain text or HTML file.

  • Command Line: ls

    The ls command lists files at the command line and gives you many useful details about file properties. With or without colors, this command keeps you on top of your files.

  • deskTOPia: tablaunch

    Desktop icons are not the only way to launch programs; in fact, a kicker that is not hidden by a muddle of windows is often preferable. Tablaunch is a flexible and attractive program launcher for the Linux desktop.

  • FreeFileSync

    Many users still fail to back up important data. FreeFileSync automatically synchronizes specified folders to multiple storage media on demand.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News