Navigate Your File System Like a Ninja with `cd -`

Quick Tip

Navigate Your File System Like a Ninja with `cd -`

Challenge: You’re deep in a directory structure, working on a task. Now you need to quickly hop back to the directory you were in just before, or maybe even further back in your recent history. Manually typing out the full path can be tedious, especially with long, complex directory names.

The Solution: Use the `cd -` command.

cd -

Why it works: The `cd -` command is a shell shortcut that takes you to the previous working directory. The shell maintains a variable (`PWD`) for the current directory and another for the previous one. `cd -` toggles between these two locations.

Pro-Tip: Combine `cd -` with `pushd` and `popd` for more advanced directory stack management. `pushd directory_name` adds the current directory to the stack and then changes to `directory_name`, while `popd` removes the top directory from the stack and changes to it.

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments