Stealthy Directory Navigation with `pushd` and `popd`

Quick Tip

Stealthy Directory Navigation with `pushd` and `popd`

Challenge: Frequently jumping between directories and losing track of where you were can be time-consuming and error-prone.

The Solution: Use the `pushd` and `popd` commands to maintain a stack of visited directories, allowing for quick returns to previous locations.

# Go to a new directory and add it to the stack pushd /path/to/new/directory # ... do some work ... # Return to the previous directory popd # Swap the top two directories on the stack and change to the new top pushd - # View the directory stack dirs 

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 returns you to it. This creates a Last-In, First-Out (LIFO) navigation system.

Pro-Tip: Use `pushd +n` to rotate the stack and change to the directory at position `n` (where `+0` is the top).

Linux Tips & Tricks | © ngelinux.com | 4/26/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments