Site icon New Generation Enterprise Linux

Effortless Directory Hopping with `cd -`

Quick Tip

Effortless Directory Hopping with `cd -`

Challenge: You’re working in a directory, then need to quickly switch to another location, only to realize you’ll need to navigate back to your original spot later. Manually tracking paths or using `cd ..` repeatedly can be tedious.

The Solution: Use `cd -` to instantly return to your previous directory.

cd -

Why it works: The shell maintains a special variable, `OLDPWD`, which stores the path of your previous working directory. `cd -` is a shorthand to navigate to the directory stored in `OLDPWD`.

Pro-Tip: Combine `cd -` with `pushd` and `popd` for managing a stack of directories you’ve visited, allowing you to easily jump between multiple locations.

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

0 0 votes
Article Rating
Exit mobile version