Member-only story
The 10 Most Productive Shell Commands and Command-Line Tricks
Shell history, editing the current line, and more
Out of free stories? Get this article for free at https://aiko.dev/shell-commands/.

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