Site icon New Generation Enterprise Linux

Seamlessly Jump Directories with `cd -`

Quick Tip

Seamlessly Jump Directories with `cd -`

Challenge: You’ve navigated through several directories, perhaps to inspect logs or copy files, and now you need to quickly return to the directory you were in just before your last `cd` command.

The Solution: Use `cd -` to instantly switch back to your previous working directory.

cd -

Why it works: The shell maintains a special variable, `OLDPWD`, which stores the path to the previous working directory. `cd -` is a shorthand for `cd “$OLDPWD”`, effectively toggling between your current and previous locations.

Pro-Tip: Combine `cd -` with `pushd` and `popd` for a more robust directory stack management. `pushd` adds the current directory to the stack, and `popd` removes it.

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

0 0 votes
Article Rating
Exit mobile version