DEV Community

Cover image for 10 Tools To Power Up Your Command Line
Darren Burns
Darren Burns

Posted on • Updated on • Originally published at darrenburns.net

10 Tools To Power Up Your Command Line

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

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) 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) is a similar project.

Installing z

  • Install bash version, on macOS (Homebrew): brew install z
  • Install fish shell version, on macOS (Fisher): fisher add jethrokuan/z

fzf, a fast fuzzy finder

After installing fzf (GitHub), 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

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): 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) is your friend. bat can be used as a drop-in replacement for cat.

bat

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

bench, for benchmarking your code

bench (GitHub) 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

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

hyperfine (GitHub) is an alternative to bench written in Rust that you might also be interested in.

Installing bench

  • On macOS using Homebrew: 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 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. 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.

asciinema_example

If you want to generate an SVG animation from your recording using svg-term (GitHub), 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 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

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: brew install wrk

exa, an alternative to ls

exa 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

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: 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) 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

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: brew install fd

rg (ripgrep), for finding strings in files

rg (GitHub) is a (much) faster alternative to grep.

rg

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: 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 and on DEV.

This post was originally published on my blog.

Top comments (49)

Collapse
 
marionebl profile image
Mario Nebl

Nice posts, thanks for the mention of svg-term-cli. I just wanted to point out that svg-term-cli does not require remote asciicasts to work.

You also have the option to pass an asciinema recording via stdin, e.g.

asciinema rec cast.json
cat cast.json | svg-term-cli
Enter fullscreen mode Exit fullscreen mode

Cheers

Collapse
 
_darrenburns profile image
Darren Burns

Thanks for the heads up Mario :)

I've updated the post!

Collapse
 
pabuisson profile image
Pierre-Adrien Buisson

Thanks for this list! I already use several of those, but some of them I didn't know. z is my favorite of the batch, use it all the time, it's a huge time saver! I also use fzf daily through the vim plugin as my default fuzzy file finder and it works great, same for bat, very useful.

As for asciinema, I noticed that on your blog, my Firefox does not render the ascii clips correctly (even though I turned all content blocking off, and the clips are rendered correctly on asciinema website).

Collapse
 
_darrenburns profile image
Darren Burns

Not sure why they don't work on Firefox :( Thanks for the heads up though. I moved back to using gifs for parts 2 and 3.

Collapse
 
pabuisson profile image
Pierre-Adrien Buisson

My pleasure! Thanks again for this article, I went and read the whole series on your blog and found many other useful tools, once again quite a bunch that I already but also new ones I'll be testing soon ;)

Thread Thread
 
marionebl profile image
Mario Nebl

Hey Pierre, any chance you could file the bug you see as issue with svg-term-cli? A screenshot of the problem and the exact FF version would be super nice.

Thread Thread
 
pabuisson profile image
Pierre-Adrien Buisson

Hey Mario! Sure, can do. I'll do it right now, happy to help.

Collapse
 
rhymes profile image
rhymes

z is definitely one of my favourites, don't use cd that much anymore. Fun fact:

➜  ~ z -l | sort -n -r | head -1
8420       /Users/rhymes/Dev/devto

bat I've aliased to cat already, wrk is the coolest and ripgrep made me replace ack.

Didn't know about the others. I've installed exa, fd and bench.

Thank you!

I feel like Rust is there for fast and powerful command line tools :D

Collapse
 
darkain profile image
Vincent Milum Jr

Some really cool stuff here! I personally just wish more of these were available on FreeBSD rather than requiring macOS.

Collapse
 
_darrenburns profile image
Darren Burns

Thanks!

Collapse
 
jesusjbr profile image
jesusjbr

These good CLI tools mostly are written in Rust. That alone give him some credit for me (in Rust we trust). Nice compilation, this is one of the best post that I've read in dev.too.

Collapse
 
miku86 profile image
miku86

Hey Darren,

thanks for your post.

I love z for the terminal.

I also love ranger as my file manager, where I set some shortcuts for specific places like "Go to Home" (gh), "Go to External Devices" (ge) etc.

Moreover I use trash-cli, so that I can delete files from the terminal savely into to the Trash.

Collapse
 
jhspetersson profile image
jhspetersson

You could probably like my tiny tool to search files with SQL queries. Another find replacement written in Rust as well.

github.com/jhspetersson/fselect

Collapse
 
_darrenburns profile image
Darren Burns

This is fantastic, I love it! Thanks for posting it :)

Collapse
 
jraynal profile image
RAYNAL JR

How does ripgrep compare to ag? I use the silver searcher almost exclusively :). Combined with fish shell wildcards that's a killer combo! I am looking forward to try some of these though.

Collapse
 
_darrenburns profile image
Darren Burns

BurntSushi (the author of rg) made a huge blog post you might be interested in.

He compares it to and benchmarks it against tools like silver searcher etc: blog.burntsushi.net/ripgrep

Collapse
 
clickclickonsal profile image
Sal Hernandez

OMG! These are some dope tools! I just installed fzf, exa, bat, & fd!

I added the aliases below to my shell profile to introduce them seamlessly into my workflow! πŸ˜€

alias cat="bat"
alias find="fd"
alias ls="exa"
alias ll="ls -alF"

Thanks for sharing this Darren! This is def going to help me boost up my workflow.

Collapse
 
ralcr profile image
Cristian Baluta

The most useful cmd for me is Jit github.com/ralcr/Jit, it allows me to make git commits with 'jit magic Blah blah' instead 3 commands. It also allows me to create branches from jira issues and switch branches by typing only the number of the task

Collapse
 
renatosuero profile image
Renato Suero

Like Ryan, I too always read posts to finding out new tools and I'd like to suggest Tig maybe it can be useful

Collapse
 
_darrenburns profile image
Darren Burns

Glad you found it useful ☺️

Tig looks cool, I'll check it out!

Collapse
 
darkain profile image
Vincent Milum Jr

By default, FreeBSD doesn't use bash Shell, it uses tcsh. Yes, it's possible to switch, but then all of the features of tcsh go bye bye, which is the entire "feel" of FreeBSD. the other thing is that a couple of these I looked into have not been ported to FreeBSD at all yet.

Collapse
 
edwardhu profile image
Edward

Thanks for your sharing!
Very useful :)

Collapse
 
mraza007 profile image
Muhammad

Cool
You mentioned great tools

Collapse
 
janpauldahlke profile image
jan paul

nice job darren, bookmarked! :-)