loading...
Cover image for 10 Tools To Power Up Your Command Line

10 Tools To Power Up Your Command Line

_darrenburns profile image Darren Burns Updated on ・6 min read

Power Up Your Command Line (4 Part Series)

1) 10 Tools To Power Up Your Command Line 2) 5 More Tools To Power Up Your Command Line (Part 2 Of Series) 3) Power Up Your Command Line, Part 3 4) 5 CLI Utilities to Boost Your Productivity

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.

Power Up Your Command Line (4 Part Series)

1) 10 Tools To Power Up Your Command Line 2) 5 More Tools To Power Up Your Command Line (Part 2 Of Series) 3) Power Up Your Command Line, Part 3 4) 5 CLI Utilities to Boost Your Productivity

Posted on by:

_darrenburns profile

Darren Burns

@_darrenburns

A software engineer living in Edinburgh, Scotland. I'm passionate about programming, learning new things (and sharing what I learn), digital art, and good sci-fi/fantasy books! πŸ’»πŸ“šπŸŽ¨βœ¨

Discussion

markdown guide
 

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

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

 

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

 

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

 
 

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.

 

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.

 

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

 

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.

 

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!

 

Thanks for your sharing!
Very useful :)

 

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

 

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.

 

Since you mentioned fzf, allow me to introduce a small CLI tool I wrote, npm-fzf. It makes npm commands easier with fzf.

github.com/hankchanocd/npm-fzf

 

I personally use fasd rather than z; it includes several similar tools as well, all attached to their respective tools, such as the original z, j, being the commend this time!

 

Hey Darren, really love this collection. Earned my β€οΈπŸ’―.

I think that z and fzf will be the greatest timesavers for me personally. But I'll check out the others too :)

Thanks for sharing πŸ™ŒπŸ»

 

You're welcome, happy to hear you enjoyed it!

 

Thanks for the post! Love me some good cli tools and there were a couple here that were new to me, gonna have to try them out!

 

Glad you found it useful Corey, hopefully they help you :)

 
 

I always love these posts about tools recommendations. I love finding out about new, useful commands! I hadn't seen a lot of these! Thanks for sharing :)

 

Thanks Ryan, glad you enjoyed it!

 

nice job darren, bookmarked! :-)

 

I know what I'm doing when I get into work tomorrow!

 

These are great, thanks Darren! The only thing I notice is that I tend to forget about all these cool commands rather quickly. Bookmarked your post to refresh my memory!

 

Thank you for sharing :) Really helpful!

 

Nice list. You should look at github.com/giltene/wrk2 as an alternative to wrk. In the README is explained why to use it instead of wrk :)

 

Ohhh this is brilliant, it does exactly what I've been looking for recently! Thanks!

 

Thanks!
I installed bat but doesn't detect React syntaxis. Does anyone know how to fix this?

 

Hi Hugo,

Thanks for your comment :)

It might be worth creating an issue over in the bat GitHub repo if you can't get JSX syntax to work. The project is supposed to highlight JSX, as there's a syntax file for it: github.com/sharkdp/bat/blob/566aab...

 

Thanks!
I found out what the problem was. The files need to have the jsx extension

 
 

Thank you! I'll be posting another one soon :)

 

Awesome post Darren! I'm going to have to give wrk a try on my next project.

 
 

Cool
You mentioned great tools

 

This is awesome!! Thanks for sharing.

Did you try the thesilverserarcher for finding I think it is a great tool

 

Hi Darren I have a question.

Would it be ok for you if I would use your information and gifs for a little presentation on a local meetup in my hometown?

Thx

 

Of course! Good luck with your presentation πŸ™‚