Effortless Directory Hopping with `cd -`

Quick Tip

Effortless Directory Hopping with `cd -`

Challenge: You’re deep within a directory structure and need to quickly switch back to the directory you were in previously, without manually typing the full path or relying on history search.

The Solution: Use the `cd -` command.

cd -

Why it works: The `cd -` command is a shortcut that navigates to the previous working directory. The shell maintains a special variable `$OLDPWD` which stores the path of the directory you were in before the last `cd` command.

Pro-Tip: Combine `cd -` with `pushd` and `popd` for a more robust directory stack management. `pushd` adds a directory to the stack, and `popd` removes it, allowing you to easily cycle through multiple previously visited directories.

Linux Tips & Tricks | © ngelinux.com | 5/16/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments