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
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:
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
.
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):
brew install 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.
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.
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):
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.
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!
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
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)
Nice posts, thanks for the mention of
svg-term-cli
. I just wanted to point out thatsvg-term-cli
does not require remote asciicasts to work.You also have the option to pass an asciinema recording via stdin, e.g.
Cheers
Thanks for the heads up Mario :)
I've updated the post!
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 usefzf
daily through the vim plugin as my default fuzzy file finder and it works great, same forbat
, 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).
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.
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 ;)
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.Hey Mario! Sure, can do. I'll do it right now, happy to help.
z
is definitely one of my favourites, don't usecd
that much anymore. Fun fact:bat
I've aliased tocat
already,wrk
is the coolest andripgrep
made me replaceack
.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
Some really cool stuff here! I personally just wish more of these were available on FreeBSD rather than requiring macOS.
Thanks!
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.
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.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
This is fantastic, I love it! Thanks for posting it :)
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.
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
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! π
Thanks for sharing this Darren! This is def going to help me boost up my workflow.
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
Like Ryan, I too always read posts to finding out new tools and I'd like to suggest Tig maybe it can be useful
Glad you found it useful βΊοΈ
Tig looks cool, I'll check it out!
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.
Thanks for your sharing!
Very useful :)
Cool
You mentioned great tools
nice job darren, bookmarked! :-)