get back to the previous location after 'cd' command?

One Two Three picture One Two Three · May 18, 2012 · Viewed 17.4k times · Source

I'm writing a shell script that needs to cd to some location. Is there any way to get back to the previous location, that is, the location before cd was executed?

Answer

Levon picture Levon · May 18, 2012

You can simply do

cd -

that will take you back to your previous location.

Some shells let you use pushdir/popdir commands, check out this site. You may also find this SO question useful.