Go back to the previous directory via command line

Feb 9, 2010 - 1 Comment

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.

Related articles:

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

One Comment

» Comments RSS Feed

  1. Murphy says:

    Just twittered this. Good one !

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

Shared on Facebook

Shop at Amazon

Ad

OSXDaily on Facebook