To use the cd - command in Bash, follow these steps:
-
Navigate to a Directory: Start by changing to a directory. For example:
cd /home/user/documents -
Change to Another Directory: Move to a different directory:
cd /home/user/downloads -
Return to the Previous Directory: Now, to go back to the directory you were just in (in this case,
/home/user/documents), simply run:cd -
What Happens:
- When you execute
cd -, Bash will switch you back to the last directory you were in and display its path.
Example in Action:
cd /home/user/documents # Current directory: /home/user/documents
cd /home/user/downloads # Current directory: /home/user/downloads
cd - # Returns to: /home/user/documents
This command is particularly useful for quickly toggling between two directories. If you have more questions or need further examples, feel free to ask!
