Filesystem Fundamentals · #7 of 19
Directory Navigation
pwd, cd, ls
The Big Three
Three commands will get you anywhere:
pwd— Print Working Directory (where am I?)cd— Change Directory (go somewhere)ls— LiSt (what’s here?)
pwd — Where Am I?
pwd
# /home/user/Documents
The output is your absolute path — your exact location in the filesystem tree.
cd — Change Directory
Basic Usage
cd /etc # Go to /etc (absolute path)
cd Documents # Go to Documents folder (relative path)
cd .. # Go up one level
cd ../.. # Go up two levels
cd ~ # Go to home directory
cd # Also goes home (shortcut)
cd - # Go to previous directory
Path Building
# If you're in /home/user
cd Documents/Work/Projects
# Now you're in /home/user/Documents/Work/Projects
cd ../../Personal
# Now you're in /home/user/Documents/Personal
ls — List Contents
Basic Usage
ls # List files and directories
ls /etc # List specific directory
ls -l # Long format (details)
ls -a # Show hidden files (.*)
ls -la # Long format + hidden files
ls -lh # Human-readable sizes (KB, MB, GB)
ls -lt # Sort by time (newest first)
ls -lS # Sort by size (largest first)
ls -R # Recursive (all subdirectories)
Understanding Long Format
-rw-r--r-- 1 user group 4096 Dec 30 10:30 document.txt
└────┬────┘ │ └──┘ └───┘ └──┘ └────┬─────┘ └─────┬─────┘
│ │ │ │ │ │ │
perms links owner group size date name
Hidden Files
Files starting with . are hidden by default:
ls -a
.bashrc .config Documents Downloads .ssh
Practical Navigation Patterns
Jumping Around
# Save location, do something, return
pushd /var/log # Save current dir, go to /var/log
# do stuff...
popd # Return to saved location
Tab Completion
cd /ho[TAB] # Completes to /home/
cd /home/u[TAB] # Completes to /home/user/
ls /etc/pas[TAB] # Completes to /etc/passwd
Wildcards
ls *.txt # All .txt files
ls *.{jpg,png} # All .jpg and .png files
ls file? # file1, file2, fileA, etc.
ls [abc]* # Files starting with a, b, or c
tree — Visual Directory Structure
Not installed by default, but very useful:
sudo apt install tree
tree # Current directory tree
tree -L 2 # Only 2 levels deep
tree -d # Directories only
tree /etc -L 1 # /etc, 1 level
Output:
.
├── Documents
│ ├── report.pdf
│ └── notes.txt
├── Downloads
└── Pictures
├── vacation
└── family
Try It!
Use the terminal below to practice navigation:
Exercises:
- Find out where you are (
pwd) - List everything including hidden files (
ls -la) - Navigate to
/etcand back home - Use
cd -to toggle between two directories - Try tab completion!
Try it: navigate the filesystem
The tree on the right redraws as you cd and ls. Goal: reach /etc and list it.