10 Tools To Power Up Your Command Line
Tags: productivity, tips, unix, commandline
Published: 2019-01-03 08:53:31

---
title: 10 Tools To Power Up Your Command Line
published: true
description: A showcase of some of the best command line tools I've discovered in recent years. If you ever use the command line, you'll probably find that at least one item on this page will make your life easier.
tags: productivity, tips, unix, commandline
series: Power Up Your Command Line
cover_image: https://thepracticaldev.s3.amazonaws.com/i/n6kfrscz8ye6dzdpho4c.png
---

This post is the first in a series of showcases of some of the best non-standard command line tools I've discovered in recent years. If you ever make use of the command line, you'll probably find that at least one item on this page will make your life easier.

## `z`, jump around

![Jump Around](https://thepracticaldev.s3.amazonaws.com/i/nmu47j5o0xjqh4b4uo52.gif)

One of the best and most ubiquitous time-saving features in modern web browsers is the fuzzy and smart search capabilities of the address bar. Want to quickly go to Twitter? Typing "tw" into your address bar and hitting enter is probably enough.

By comparison, the standard way of navigating our file systems via the command line (using `cd`) seems almost prehistoric. Thankfully, `z` ([GitHub](https://github.com/rupa/z)) brings this browser-style navigation to the command line.

After a short learning period, `z` will allow you to jump to a directory *from anywhere*, using only a substring of the target directory name. The directory that `z` will take you to is determined by the string argument you gave it, how *frequently* you visit the directory, and how *recently* you visited the directory. They call it *"frecency"*.

`z` not only increases the speed at which you can navigate your filesystem, it reduces the cognitive load of navigation. With `cd`, you need to recall precisely where the destination directory sits in the tree, and work out the path to get there. With `z`, knowing the name of the directory is enough.

Ports of `z` to other shells (such as fish and zsh) are readily available too. `autojump` ([GitHub](https://github.com/wting/autojump)) is a similar project.

### Installing `z`

* Install `bash` version, on macOS ([Homebrew](https://brew.sh)): `brew install z`
* Install `fish` shell [version](https://github.com/jethrokuan/z), on macOS ([Fisher](https://github.com/jorgebucaran/fisher)): `fisher add jethrokuan/z`

## `fzf`, a fast fuzzy finder

After installing `fzf` ([GitHub](https://github.com/junegunn/fzf)), you can press `Ctrl + T` at any point in time to open up an interactive fuzzy search interface, which will recursively search for files inside the current directory. You can enter a search term, and press the up/down keys to move through the results. If you press the enter key, the selected result is inserted into your terminal:

![fzf](https://thepracticaldev.s3.amazonaws.com/i/lasfcsdm1yswprwkuybg.gif)

In the example above, I typed `bat` (but this could be any command, such as `less`, `cd`, etc.), then pressed `Ctrl + T`. I typed `five`, hit enter, and the path `src/five.rs` was inserted at my cursor position. This saves the alternative of (roughly): type `src`, press tab, type `fi`, press tab, which doesn't scale to long or hard to remember paths.

### Installing `fzf`

* On macOS ([Homebrew](https://brew.sh)): `brew install fzf`
* Bindings for `fish`: `fisher add jethrokuan/fzf`

## `bat`, to view files with syntax highlighting

If you want to quickly view a source file with full syntax highlighting, `bat` ([GitHub](https://github.com/sharkdp/bat)) is your friend. `bat` can be used as a drop-in replacement for `cat`.

![bat](https://thepracticaldev.s3.amazonaws.com/i/n28wzi9fctdbodglgfhx.gif)

If the output is large enough (as in the example above), `bat` will pipe it's output into `less`, meaning we get pagination for free!

### Installing `bat`

* On macOS ([Homebrew](https://brew.sh)): `brew install bat`

## `bench`, for benchmarking your code

`bench` ([GitHub](https://github.com/Gabriel439/bench)) is an incredibly useful tool for benchmarking your code. It's written in Haskell, which makes it the coolest thing on this page. You can pass any command you can run from your terminal to it (in quotes), and it will measure the execution time by repeatedly running the command. When it's finished, it'll output useful statistics to your terminal.

![bench](https://thepracticaldev.s3.amazonaws.com/i/vd9iqp1012k6om51h99b.gif)

This is a considerably more powerful means of measuring the execution time of your code than the built-in `time` command.

`hyperfine` ([GitHub](https://github.com/sharkdp/hyperfine)) is an alternative to `bench` written in Rust that you might also be interested in.

### Installing `bench`

* On macOS using [Homebrew](https://brew.sh): `brew install bench`

## `asciinema` & `svg-term`, for recording your terminal as an SVG animation

The terminal clips on the version of [this post on my personal blog](https://darrenburns.net/posts/tools) are SVG animations (unfortunately dev.to doesn't support SVG uploads)! You'll notice they're much crisper than the gifs on this page. Using SVG rather than a video format or gif has several huge benefits:

* Perfect quality regardless of zoom 🔍
* We can put them in Markdown files like any other image 😱
* Smaller file sizes compared to video formats and gifs 🧐
* SVG animations are *way* cooler than videos 🔥

To record the terminal, I use [`asciinema`](https://asciinema.org). Begin recording with `asciinema rec`. When you're finished, press `Ctrl+D`, and you'll be given the options of either saving the recording locally or uploading it to [asciinema.org](https://asciinema.org).

![asciinema_example](https://thepracticaldev.s3.amazonaws.com/i/1a83p0nleldkd6ug4uvy.gif)

If you want to generate an SVG animation from your recording using `svg-term` ([GitHub](https://github.com/marionebl/svg-term-cli)), and you uploaded your recording to asciinema, you'll have to make it public by visiting the resulting link.

To convert the recording to an SVG animation, you can supply the ID of the cast (available on the asciinema page after making it public - the ID is in the URL), an output file, and numerous other optional arguments. For example, to save the terminal recording at [https://asciinema.org/a/219486](https://asciinema.org/a/219486) to the SVG file you see in the example above, I used:

```
svg-term --cast=219486 --out ~/somewhere/out.svg --padding 18 --height 8 --width 80
```

Alternatively, if you don't want to upload your recording to asciinema, you can supply a local cast file directly to `svg-term` (thanks to Mario Nebl, the author of `svg-term` for pointing this out to me):

```
asciinema rec cast.json
cat cast.json | svg-term-cli
```

### Installing `asciinema` & `svg-term`

* Installing `asciinema` on macOS: `brew install asciinema`
* Installing `svg-term` on macOS: `npm install -g svg-term-cli`

## `wrk`, for benchmarking your HTTP APIs

This is a handy little tool for performance testing your API. To demonstrate, I've got a minimal Python HTTP API server with a single endpoint (`GET /hello`) running on my local machine at port 8001. We can check how well the `/hello` endpoint performs using `wrk` (with 12 threads, 200 connections, for 5 seconds):

![wrk](https://thepracticaldev.s3.amazonaws.com/i/zwk2fopv1cgw27740j1a.gif)

You can tweak the number of threads, connections, and the duration of your test to check performance under different loads. It's not a replacement for performance testing tools such as Locust and JMeter, but it's lightweight and will suffice in many situations.

Unfortunately, the command line interface for `wrk` makes it somewhat awkward to perform POST requests. If you want to do that, you'll need to write a small Lua script and supply it to the command as an argument (there's more information in the docs).

### Installing `wrk`

* On macOS using [Homebrew](https://brew.sh): `brew install wrk`

## `exa`, an alternative to `ls`

[`exa`](https://the.exa.website) is a modern replacement for `ls` with colour-coded output that's a little easier on the eye, and a larger variety of options for controlling how output is presented.

![Exa](https://thepracticaldev.s3.amazonaws.com/i/3eseuz5vx6fc7294tboj.gif)

It supports features such as respecting your *.gitignore* files via the `--git-ignore` flag, and printing
out a directory as a tree structure with the `-T` flag (see above). It even shows the git status of files!

### Installing `exa`

* On macOS using [Homebrew](https://brew.sh): `brew install exa`

## `fd`, for finding files & directories

If you're looking for a file or directory, you'd usually use the `find` command to perform a search based on a regular expression. `fd` ([GitHub](https://github.com/sharkdp/fd)) is an alternative to `find` written in Rust which offers a more convenient interface by using sensible defaults, and it's faster to boot!

![fd](https://thepracticaldev.s3.amazonaws.com/i/ojytfn8zszkjw51r8x9x.gif)

It'll respect your *.gitignore* files, and it supports parallel command execution, which lets you execute a terminal command (in parallel) for every file or directory returned for a search. For example (from the `fd` documentation), to find all .jpg files and convert them to .png files in parallel using the Unix `convert` command, you can run:

```
fd -e jpg -x convert {} {.}.png
```

### Installing `fd`

* On macOS using [Homebrew](https://brew.sh): `brew install fd`

## `rg` (ripgrep), for finding strings in files

`rg` ([GitHub](https://github.com/BurntSushi/ripgrep)) is a (*much*) faster alternative to `grep`.

![rg](https://thepracticaldev.s3.amazonaws.com/i/cmpd8gleajtbj2ycz96n.gif)

`rg` is written in Rust, and it powers the search functionality inside the VS Code text editor. It consistently outperforms similar tools in benchmarks.

### Installing ripgrep

* On macOS using [Homebrew](https://brew.sh): `brew install ripgrep`

## Conclusion

Hopefully you found something useful in this post! If you’re interested in more content like this, follow me on [Twitter](https://twitter.com/_darrenburns) and on [DEV](https://dev.to/_darrenburns).

This post was originally published on my [blog](https://darrenburns.net).