Site icon New Generation Enterprise Linux

Effortless Directory Hopping with `cd -` and `pushd`/`popd`

Quick Tip

Effortless Directory Hopping with `cd -` and `pushd`/`popd`

Challenge: Frequently navigating back and forth between directories can be cumbersome, requiring you to remember and retype full paths.

The Solution: The `cd -` command and the `pushd`/`popd` built-ins offer efficient ways to manage directory history.

# To quickly jump back to the previous directory cd - # To manage a stack of directories pushd /path/to/directory1 pushd /path/to/directory2 # You are now in directory2, with directory1 in the stack popd # You are now back in directory1 popd # You are now in your original directory 

Why it works: `cd -` is a shortcut that directly switches to the directory stored in the `$OLDPWD` environment variable. `pushd` adds the current directory to a stack and then changes to the specified directory, while `popd` removes the top directory from the stack and changes to it.

Pro-Tip: Use `dirs -v` to view the directory stack managed by `pushd` and `popd`.

Linux Tips & Tricks | © ngelinux.com | 6/1/2026

0 0 votes
Article Rating
Exit mobile version