Linux – push/pop current directory

bashlinux

With bash is there a way to push and pop the current working directory? I tried writing bash;cd dir; ./dostuff;exit; but the current directory is now dir.

Best Answer

There is pushd and popd

Bash will keep a history of the directories you visit, you just have to ask. Bash stores the history in a stack and uses the commands pushd and popd to manage the stack.

More to read

Example:

$ pwd; pushd /tmp; pwd; popd; pwd
/home/me
/tmp ~
/tmp
~
/home/me
Related Question