Go back to the previous directory via command line

Feb 9, 2010 - 2 Comments

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:

cd -

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!

mac terminal icon 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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Bill Ellis in Command Line, Mac OS X

2 Comments

» Comments RSS Feed

  1. Murphy says:

    Just twittered this. Good one !

  2. Ruel says:

    Been finding this! Thank you so much!

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates