Quick Directory Hopping with `cd -`

Quick Tip

Quick Directory Hopping with `cd -`

Challenge: You’ve navigated deep into a directory structure and need to quickly return to the previous directory you were in without remembering the full path.

The Solution: Use the `cd -` command.

cd -

Why it works: The shell maintains a special variable, `OLDPWD`, which stores the path of the previously current working directory. `cd -` is a shortcut to `cd $OLDPWD`.

Pro-Tip: Combine this with `pushd` and `popd` for managing a stack of directories, allowing you to easily switch between multiple locations.

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments