cd — Navigate the Linux Filesystem
Master the cd command: absolute paths, relative paths, home shortcuts, the parent directory, and the cd - trick that saves you every day.
cd (Change Directory) is the command you'll type more than almost any other. It moves you through the filesystem tree. Like walking between rooms — except you can teleport to any room instantly by knowing its full address.
Syntax
cd [DIRECTORY]
# cd is a shell builtin — use "help cd" not "man cd"
help cdSpecial Shortcuts
cd Special Arguments
| Shortcut | Description | Expands To |
|---|---|---|
cd | Go home (no argument) | cd /home/sagar |
cd ~ | Go home (explicit) | cd /home/sagar |
cd .. | Go up one level | Parent directory |
cd ../.. | Go up two levels | Grandparent directory |
cd - | Toggle to previous directory | Last place you were |
cd . | Stay in place (no-op) | Current directory |
Absolute vs Relative Navigation
# ─── Absolute paths (start with /) ──────────────────────────
cd /home/sagar/Documents # Full path from root
cd /etc # System config directory
cd /var/log # Log files
cd / # The root itself
# ─── Relative paths (from where you currently are) ───────────
# Assuming you're in /home/sagar:
cd Documents # → /home/sagar/Documents
cd Documents/work # → /home/sagar/Documents/work
# Assuming you're in /home/sagar/Documents:
cd .. # → /home/sagar
cd ../Downloads # → /home/sagar/Downloads
cd ../../etc # → /etc (up 2, then into etc)
# ─── Home directory ──────────────────────────────────────────
cd # Go home — fastest way!
cd ~ # Same thing, explicit ~
cd ~/Projects/myapp # Go to a project folder
# ─── Back and forth ──────────────────────────────────────────
cd /var/log
cd /etc/nginx
cd - # → /var/log
cd - # → /etc/nginx (keeps toggling!)Real-World Patterns
These are the cd patterns you'll use every day in real work:
# Pattern 1: Go to project, work, return to where you were
cd ~/Projects/backend
# ... edit files, run tests ...
cd - # Back to previous directory instantly
# Pattern 2: Navigate to sibling directory
# Currently in: /home/sagar/Documents
cd ../Downloads # Sibling — go up then sideways
# Pattern 3: Deep jump, then home
cd /var/lib/docker/volumes/abc123/_data
# deep work...
cd # Instant jump home, don't type the path
# Pattern 4: Tab completion (essential!)
cd /ho → Tab → /home/
cd /home/sa → Tab → /home/sagar/
cd /home/sagar/Pro → Tab → /home/sagar/Projects/cd Has No man Page
cd is a shell builtin — it's built into bash/zsh itself, not an external program. That's why man cd typically opens a generic page or fails. Use help cd (bash) or run-help cd (zsh) to see the real documentation.
You're in `/home/sagar/Projects/backend/src`. Which command takes you to `/home/sagar/Projects/frontend`?
What does `cd -` do?
Navigation drill — complete each step without using the up arrow:
- Go to
/var/log - Without typing the full path, go to the sibling
/var/cache - Jump back to
/var/logusing one keystroke/command - Go three levels deep into your home directory (create folders if needed)
- Return home with a single command