The Bash directory stack keeps a short list of working directories inside the current shell, so a terminal can move between related paths without retyping each absolute path. It fits interactive work where editing source files, reading logs, and returning to a project root happen in the same shell session.
The pushd builtin changes directory and puts the previous location on the stack. The dirs -v command shows numbered stack entries with the current directory at index 0, and popd removes the top entry so Bash returns to the directory beneath it.
The stack belongs to the shell session that created it, so entries do not persist after that shell exits. The command sequence uses temporary directories and default Bash builtins only, then removes the test tree after the stack behavior is confirmed.
Related: How to manage Bash command history
Related: How to create and use aliases in Bash
$ mkdir -p /tmp/bash-guides/use-directory-stack/app /tmp/bash-guides/use-directory-stack/logs $ cd /tmp/bash-guides/use-directory-stack
$ pwd /tmp/bash-guides/use-directory-stack
$ pushd app /tmp/bash-guides/use-directory-stack/app /tmp/bash-guides/use-directory-stack
Bash prints the directory stack after a successful pushd command.
$ dirs -v 0 /tmp/bash-guides/use-directory-stack/app 1 /tmp/bash-guides/use-directory-stack
$ pushd ../logs /tmp/bash-guides/use-directory-stack/logs /tmp/bash-guides/use-directory-stack/app /tmp/bash-guides/use-directory-stack
$ dirs -v 0 /tmp/bash-guides/use-directory-stack/logs 1 /tmp/bash-guides/use-directory-stack/app 2 /tmp/bash-guides/use-directory-stack
Use dirs -v before popd when several stack entries are present and the next return point is not obvious.
$ popd /tmp/bash-guides/use-directory-stack/app /tmp/bash-guides/use-directory-stack
$ pwd /tmp/bash-guides/use-directory-stack/app
$ popd /tmp/bash-guides/use-directory-stack
$ cd /tmp
$ rm -r /tmp/bash-guides