Go back to the previous directory via command line
It’s easy to accidentally change directories to something you weren’t intending to (say, accidentally hitting cd and returning home and losing your place in a complicated directory structure), but thankfully there’s a command that will immediately take you back to the previous directory:
It’s that simple, cd – will take you to the directory you were in prior to the PWD, and it will print out the prior directory before you so you will know you’re in the right place. This is very useful if you are working in two different directories and you want to quickly go back and forth between them, just keep typing cd – and you will keep switching between the two directories!
This command line tip works in every variant of Unix I’ve used, so whether you’re in the Mac OS X command line or Linux, you should be covered.