Go back to previous directory in Terminal

When working with macOS or Linux terminal you often end up switching between two directory. Especially when the directories are far apart in the file tree, changing from one directory to another can take several keystrokes. From browsing the web you are probably used to something better. Just one click on your third mouse button or a gesture on the trackpad and you navigate to the previous visited webpage.

This week I found out that this is as well possible with the terminal:

cd -

Congrats! From now on you will be a little more productive when working in shell.

Some more useful hacks:

# Change to home directory
cd

# To run the same command again 
!!

# See the output on screen and also write to a log file
mycoolapp arg1 arg2 input.file | tee my.log

# If you need a reminder to leave your terminal
leave +hhmm