Changing Directories (cd)
The cd command changes your current working directory. It's how you navigate through the Linux filesystem.
Basic Usage
cd directory_name
Navigation Shortcuts
| Command | Description |
|---|---|
cd | Go to home directory |
cd ~ | Go to home directory |
cd / | Go to root directory |
cd .. | Go up one directory |
cd ../.. | Go up two directories |
cd - | Go to previous directory |
Absolute vs Relative Paths
Absolute Paths (start with /)
cd /home/user/documents
cd /etc
cd /var/log
Relative Paths (from current location)
cd documents # Into documents subfolder
cd ../projects # Up one, then into projects
cd ./scripts # Into scripts (. is optional)
Exercise: Navigate Directories
Navigate from your home directory to the projects directory:
Common Patterns
Return Home Quickly
cd # Just cd with no arguments
cd ~ # Using the tilde shortcut
Toggle Between Directories
cd /var/log
cd /etc
cd - # Back to /var/log
cd - # Back to /etc
Navigate Deep Structures
cd projects/web-app # Multiple levels at once
cd ../../documents # Up and into another folder
Exercise: Go Back Home
After navigating somewhere else, return to your home directory:
Tab Completion
When typing paths, use Tab to autocomplete:
- Type
cd doc - Press
Tab - Shell completes to
cd documents/
This saves time and prevents typos!
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
No such file or directory | Path doesn't exist | Check spelling, use ls first |
Not a directory | Target is a file | Check the target with ls -l |
Permission denied | No access | Check permissions, use sudo if needed |
Key Takeaways
cdchanges your current directory- Use
cdorcd ~to go home - Use
cd ..to go up one level - Use
cd -to go to previous directory - Tab completion helps with long paths

