Directory stacks in bash

After looking at some shell scripts today it seems the very handy pushd and popd aren't used enough in the wild.

If you're just popping into a new directory for a moment to do something, then want to return to the directory you came from, use pushd newdir; it will push the current directory to the top of the directory stack (actually the DIRSTACK environment variable) and cd you there.

When you're done, use popd to go back to where you came from. Obviously you can keep pushing onto the stack and nest your directory changes deeper. Never again shall you need to manually remember $PWD!

ianw@lime:~$ pushd /tmp
/tmp ~
ianw@lime:/tmp$ echo do something in /tmp
do something in /tmp
ianw@lime:/tmp$ popd