25

Possible Duplicate:
Go back to previous directory in shell
How can I change to the previous directory instead of going up?

is there a command line way to navigate back to the directory I was in?

I frequently do cd .. to go up a directory, but sometimes I accidentally just do cd which takes me to the user's home directory.

I want to go back to the directory I was just in, without navigating all the way through the nested folders or without typing the whole path out, which can be very long and prone to errors

I am specifically using OSX, but cd is pretty universal

  • Try tipying a cd /? on your OSX. I did it on Windows but cd don't have such feature. – Diogo Jun 11 '12 at 15:40
  • @Diogo That command does not work on OS X (or any Unix/Linux). – slhck Jun 11 '12 at 16:17
  • @slhck I never used OSX so I really dont know.. My intent was to tell to type a cd -help or something like this to show cd manual. – Diogo Jun 11 '12 at 16:26
52

On *nix systems, you can type cd - to return to the previous directory. Doesn't work on Windows, though.

  • 1
    it does on git bash for windows (at least now in 2019). thanks for the tip – keinabel Jan 28 '19 at 11:57
14

Try:

cd -

That works in Bash. It may work in your shell too.

Not the answer you're looking for? Browse other questions tagged or ask your own question.