Site icon New Generation Enterprise Linux

Navigate Up the Directory Tree Like a Pro with `cd -`

Quick Tip

Navigate Up the Directory Tree Like a Pro with `cd -`

Challenge: You’re deep within a directory structure, working on a file, and need to quickly jump back to the directory you were in previously. Repeatedly typing `cd ../../..` can be tedious and error-prone.

The Solution: Use the `cd -` command to instantly switch to the previous working directory.

cd -

Why it works: The shell maintains a special variable, `$OLDPWD`, which stores the path to your previous directory. The `cd -` command is a shortcut that directly uses this variable to change your current directory.

Pro-Tip: You can also use `pushd` and `popd` to maintain a stack of directories, allowing you to jump between multiple locations with ease. For example, `pushd /path/to/new/directory` followed by `popd` will return you to your original location.

Linux Tips & Tricks | © ngelinux.com | 4/30/2026

0 0 votes
Article Rating
Exit mobile version