How does the 'cd -' command work in Linux?

The cd - command in Linux is used to switch to the previous directory you were in. When you execute this command, it takes you back to the last directory you navigated from, allowing you to quickly toggle between two directories.

Example:

  1. Suppose you are in /home/user/documents.
  2. You then change to /var/log using cd /var/log.
  3. If you now run cd -, you will return to /home/user/documents.

This command is particularly useful for quickly navigating back and forth between two locations in the file system.

0 Comments

no data
Be the first to share your comment!