cd changes your current directory. It's how you move around in Terminal.
Basic Usage
cd foldername
Moves into that folder.
Essential Shortcuts
| Command | Goes to |
|---|---|
cd |
Home directory |
cd ~ |
Home directory |
cd .. |
Parent directory (up one level) |
cd - |
Previous directory |
cd / |
Root of the filesystem |
Go Home
Three ways to get home:
cd
cd ~
cd \$HOME
All do the same thing - take you to /Users/yourname.
Go Up
cd ..
One level up.
cd ../..
Two levels up.
cd ../../..
Three levels up.
Go to Previous Directory
cd -
Jumps back to wherever you were before. Great for switching between two folders.
Absolute vs Relative Paths
Absolute (starts from root /):
cd /Users/john/Documents/Projects
Relative (starts from current location):
cd Documents/Projects
Use absolute when you know the full path. Use relative when navigating nearby.
Common Destinations
cd ~/Desktop
cd ~/Downloads
cd ~/Documents
cd /Applications
cd /tmp
Tab Completion
Type part of a folder name and press Tab:
cd Docu[Tab]
Completes to:
cd Documents/
If multiple matches, press Tab twice to see options.
Folders with Spaces
Spaces need quotes or escaping:
cd "My Folder"
cd My\ Folder
Or use Tab completion - it handles this automatically.
Check Where You Are
After moving around:
pwd
Shows your current location (print working directory).
Go to a Path from Finder
Drag a folder from Finder into Terminal - it types the path for you.
Or:
- Right-click folder in Finder
- Hold Option
- Click "Copy as Pathname"
- Type
cdand paste
Common Patterns
# Go to project, do work, come back
cd ~/Projects/myapp
# do stuff
cd -
# Navigate relative to current
cd src/components
# Jump to any deeply nested folder
cd /Users/john/Projects/app/src/components/ui
Errors
"No such file or directory":
- Folder doesn't exist
- Typo in the name
- You're in the wrong location
Check with ls to see what's actually there.
Combining with Other Commands
# Go somewhere and list contents
cd ~/Downloads && ls -la
# Go to project root
cd "\$(git rev-parse --show-toplevel)"
Quick Reference
| Command | Result |
|---|---|
cd folder |
Enter folder |
cd |
Go home |
cd .. |
Go up one level |
cd - |
Go to previous location |
cd ~/Desktop |
Go to Desktop |
pwd |
Show current location |
Keep Learning
Navigation is fundamental. The free course covers cd and the other commands you'll use daily.
Check it out at Mac Terminal for Humans.