Site icon New Generation Enterprise Linux

Dynamic Directory Jumping with `pushd` and `popd`

Quick Tip

Dynamic Directory Jumping with `pushd` and `popd`

Challenge: Frequently navigating back and forth between multiple directories can be cumbersome, requiring repeated `cd` commands and remembering directory paths.

The Solution: Utilize the `pushd` and `popd` shell builtins to manage a stack of directories, allowing for quick returns to previously visited locations.

# Navigate to a directory and add it to the stack pushd /path/to/directory1 # Navigate to another directory and add it to the stack pushd /another/path/to/directory2 # Return to the previous directory in the stack popd # Return to the directory before that 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 creating a history of visited directories that can be easily revisited.

Pro-Tip: Run `dirs -v` to view the directory stack and `pushd +n` to jump to the nth directory in the stack.

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

0 0 votes
Article Rating
Exit mobile version