Command line, go back to last directory [duplicate]

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


Solution 1:

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

Solution 2:

Try:

cd -

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