Better Programming

Advice for programmers.

Follow publication

Member-only story

The 10 Most Productive Shell Commands and Command-Line Tricks

Aiko Klostermann
Better Programming
Published in
4 min readApr 4, 2021

Out of free stories? Get this article for free at https://aiko.dev/shell-commands/.

GIF of commands in the terminal

When developing software, no matter what technology you are working with, there is no way around using the command line if you want to be a productive developer.

This a list of my favorite and most used shell commands and tricks that I’ve learned over the years. I’m sure you know some of them already, so feel free to skip those, but others might bring you a productivity boost and let you show off your 1337 h4x0r $killz in front of your n00b colleagues.

Disclaimer: I use these commands on macOS with Z Shell in Iterm2. As long as you are running a bash-like shell on a Unix & -like OS, these commands should work for you as well. If you have a more exotic setup, you probably know your way around the shell to make these work yourself. If you run Powershell on Windows, good luck!

cd -

You probably know that you can use cd to change into a certain directory.
But did you know you can use the dash (-) as an argument to go back to the previous directory?

$ cd /home
~> home
$ cd /my_dir
~> /my_dir
$ cd -
~> /home

Bonus tip: The dash argument also works with git checkout, so you can e.g. use it to switch quickly between master and a working branch.

For a larger directory history, check out pushd and popd.

Shell History

This is probably my most used shell trick: Press the up arrow (successively) to select the last commands in my shell history.

You can also press ctrl + r (successively) to reverse-search through your shell history by keyword in LRU order.

Or type history directly to see the whole shell history in your terminal. You can then write ![number] to select the command at position number in your history.

You can even use a negative number as that index to select the k-th last command, like so:

$ echo second
$ echo last

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (12)

Write a response