RSS

Command Line for the 21. Century: The Low Hanging Fruit

30 Oct

UPDATE (23-May-2019): Added information about moreutils.

UPDATE (9-Jan-2019): Added information about exa, hyperfine, PathPicker, and svg-term-cli utilities.

UPDATE (19-Nov-2018): Added information about the Pipe Viewer utility.

People who use Unix since 1980s, or GNU/Linux since 1990s know that they can rely on the command line and many utilities for a lot of daily automation and data processing tasks. As someone who’s been using Unix and GNU/Linux based systems since 1994, I’m more than happy that I can count on these tools and the stable know-how built on them. Nevertheless, I think the command line and TUIs (Text-based User Interfaces) can be a bit better in 21. century. Therefore, in this post, I’ll list a few recent utilities that helps us to have a better command line experience.

Before you dive into the list, please be aware that I’m after the low-hanging fruit, that is, tools that can make an existing Unix / Linux command line environment a bit better with the least disruption. In other words, I will not touch on how to have brand new, GPU-powered terminal emulators such as alacritty and kitty, and neither will I talk about how nice it’d be if you only changed your shell from Bash into fish, or elvish. (If you really want to know about alternative shells, please read https://github.com/oilshell/oil/wiki/ExternalResources and http://www.oilshell.org/blog/2018/01/28.html.) I also won’t send you down the rabbit hole and make you spend countless hours customizing your shell prompt (that requires an article by itself, but in the meantime you can go and check Go Bullet Train (GBT), you’ve been warned!). Finally, no, I won’t be talking about tmux, too, because it has books dedicated to it such as “The Tao of tmux” and “tmux 2: Productive Mouse-Free Development“.

If you think something is missing and fits within the context of “low-hanging fruit” (see above), please add a comment at the end of this post. Also, for a more specialized domain, see my recent post titled “Data Processing Resources: Command-line Interface (CLI) for CSV, TSV, JSON, and XML“.

So let’s start with cd command, and how it can be enhanced with context and history, together with fuzzy matching:

–  🚀 enhancd v2 : A next-generation cd command with an interactive filter. URL https://github.com/b4b4r07/enhancd (Similar to autojump and fasd.)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

fzf: A command-line fuzzy finder. For me, more of a nice Ctrl+r replacement for Bash reverse history search. URL: https://github.com/junegunn/fzf

fzy: A better fuzzy finder. For me, this is more of an integration tool with enhancd v2. URL: https://github.com/jhawthorn/fzy

Quickly finding files is also a very regular task, and we can always rely on the find utility, but we can have a slightly more ergonomic version:

fd: a simple, fast and user-friendly alternative to find. URL: https://github.com/sharkdp/fd/. Also see the screencast.

Whenever I need to use a command line program that I haven’t used for a while, I need to refresh my memory, and probably read at least one man page. But even for commands such as tar, reading a man page can trigger a TL;DR (Too Long; Didn’t Read) reaction. Therefore, tealdeer to the rescue:

tealdeer: A very fast implementation of tldr in Rust. For me, this is the quick go to reference before checking a man page of command line program. URL: https://github.com/dbrgn/tealdeer

Another command that I frequently use is cat, and it’s great that we can rely on an enhanced cat nowadays:

bat: A cat(1) clone with wings. I think this utility is good enough to move the official cat to the attic and use in only rare circumstances.

Every now and then, I check how much disk space is left, or which directory is consuming the biggest amount. Back in the day, I used df and du for this, and I also like the more interactive version that’s called ncdu, but nowadays I think the following tiny terminal file manager can also be used for that task:

nnn: probably the fastest and most resource-sensitive file manager you have ever used. It integrates seamlessly with your DE and favourite GUI utilities, has a unique navigate-as-you-type mode with auto-select, disk usage analyzer mode, bookmarks, familiar navigation shortcuts, subshell spawning and much more. It also lets you preview a file using whichever previewer you want. You can use bat, or even emacsclient (that is, if you, like me, prefer to have your Emacs server started, first thing after booting).

One other frequent task, in addition to navigating around your directories, and files is searching for strings and patterns in them. You always have the venerable grep tool, but nowadays, we have nice alternatives such as ripgrep:

ripgrep: a faster grep / ag / git grep / ucg / pt / sift. See for yourself at https://github.com/BurntSushi/ripgrep.

Another tool that I and many other people use very frequently is Git, a version-control system for tracking changes in computer files. And when using Git, as well as other similar tools, seeing what changed in a particular file is important. Normally you rely on your favorite Git tool to compare two versions of a file, but if you need to quickly compare two files on the command line, independent of your Git tool, you can rely on:

icdiff: improved, colored diff, for side-by-side diff view. URL: https://github.com/jeffkaufman/icdiff (You can also give diff-so-fancy a try for a human-readable diff view)

Next in line, we have an alternative for the venerable ping utility. I think having a bit more information from ping wouldn’t hurt:

prettyping: runs the standard ping in background and parses its output, showing ping responses in a graphical way at the terminal (by using colors and Unicode characters).  It’s written in bash and awk, and should work out-of-the-box in most systems (Linux, BSD, Mac OS X, …). It is self-contained in only one file, so it is trivial to install and run. (You can also give gping a try).

Another relatively less known tool is pv , the pipe viewer: it  is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion:

pv

One thing that I also do at the command line is to trigger an event whenever there’s some change to some files & directories. Of course, you can watchfor things, and even utilize inotify subsystem, but maybe you’ll find the following more convenient to quickly build a command line event triggering system:

entr: Run arbitrary commands when files change. URL: http://www.entrproject.org/ (You can also give the following a try: on-change and fswatch)

And finally, a few honorable mentions:

glances : a cross-platform, modern system monitoring tool that demonstrates the power of TUI. See https://nicolargo.github.io/glances/ for screenshots and its many features.

exa: a modern replacement for ls. It’s an improved file lister with more features and better defaults. It uses colours to distinguish file types and metadata. It knows about symlinks, extended attributes, and Git. And it’s small, fast, and just one single binary. Source code is also available at https://github.com/ogham/exa.

hyperfine: A command-line benchmarking tool (inspired by bench). When GNU time, or GNU Bash’s built-in time simply doesn’t cut it.

PathPicker: accepts a wide range of input — output from git commands, grep results, searches — pretty much anything.After parsing the input, PathPicker presents you with a nice UI to select which files you’re interested in. After that you can open them in your favorite editor or execute arbitrary commands.

svg-term-cli: Share terminal sessions as razor-sharp animated SVG everywhere. Useful for demonstrations and information sharing, error-reporting, etc.

moreutils: “a growing collection of the Unix tools that nobody thought to write long ago when Unix was young.” Once you get used to them, you’ll wonder how you managed to live without them.

 

Advertisements
 
1 Comment

Posted by on October 30, 2018 in Linux

 

Tags: , , ,

One response to “Command Line for the 21. Century: The Low Hanging Fruit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: