Effortless Directory Hopping with `pushd` and `popd`
Quick Tip
Effortless Directory Hopping with `pushd` and `popd`
Challenge: Constantly navigating back and forth between several directories can be tedious and error-prone, involving multiple `cd` commands and remembering paths.
The Solution: Use the `pushd` and `popd` built-in shell commands to manage a stack of directories.
# Push the current directory onto the stack and change to a new one pushd /path/to/another/directory # Push another directory onto the stack pushd /path/to/yet/another/place # View the directory stack dirs # Pop back to the previous directory in the stack popd # Pop back again popd
Why it works: `pushd` adds the current directory to a stack and then changes to the specified directory. `popd` removes the top directory from the stack and changes to it, effectively undoing the `pushd` operation. This creates a navigable history of visited directories.
Pro-Tip: Use `pushd +n` to rotate directories in the stack, bringing the nth directory to the top and then changing to it.
Linux Tips & Tricks | © ngelinux.com | 5/25/2026
