File System Navigation
Master pwd, ls, and cd — the three commands you'll use hundreds of times a day.
What You'll Learn
- pwd — know where you are at all times
- ls — list files with options (-l, -a, -h)
- cd — move between directories
- Absolute vs relative paths
pwd and ls — Where Am I? What's Here?
🗺️ Real-World Analogy: Think of the file system as a building. pwd tells you which room you're in. ls shows you everything in that room. cd lets you walk to another room.
pwd (Print Working Directory)
$ pwd /home/user/projects
ls (List) — Essential Options
$ ls # Basic listing $ ls -l # Long format (permissions, size, date) $ ls -a # Show hidden files (starting with .) $ ls -la # Combine: long format + hidden files $ ls -lh # Human-readable sizes (KB, MB, GB) $ ls -lt # Sort by modification time (newest first) $ ls -lS # Sort by file size (largest first) $ ls *.js # List only .js files (glob pattern)
Reading ls -l Output
drwxr-xr-x 5 user group 4096 Mar 18 09:00 Documents │└┬─┘└┬┘└┬┘ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └ Name │ │ │ │ │ │ │ │ └ Modified date │ │ │ │ │ │ │ └ Size in bytes │ │ │ │ │ │ └ Group owner │ │ │ │ │ └ File owner │ │ │ │ └ Number of links │ │ │ └ Others permissions │ │ └ Group permissions │ └ Owner permissions └ d=directory, -=file, l=link
pwd & ls
See how pwd and ls commands work with different options.
// File System Navigation — simulated
console.log("=== pwd — Print Working Directory ===");
console.log("$ pwd");
console.log("/home/user/projects");
console.log(" → Shows your current location in the file system");
console.log();
console.log("=== ls — List Directory Contents ===");
console.log("$ ls");
console.log("Documents Downloads Pictures projects");
console.log();
console.log("$ ls -l (long format with details)");
console.log("drwxr-xr-x 5 user user 4096 Mar 18 09:00 Documents");
...cd — Moving Around
cd (change directory) is how you move through the file system. Master these shortcuts:
$ cd Documents # Enter a subdirectory $ cd .. # Go up one level $ cd ../.. # Go up two levels $ cd ~ # Go to home directory $ cd / # Go to root directory $ cd - # Toggle to previous directory
Absolute vs Relative Paths
# Absolute: starts from / (always works, regardless of where you are) $ cd /home/user/projects/webapp/src # Relative: starts from your current location $ cd projects/webapp/src # if you're in /home/user $ cd ./src # . means "current directory" $ cd ../../other-project # go up 2 levels, then into other-project
⚠️ Common Mistake
cd into a file will fail — you can only cd into directories. If you see "Not a directory", check your path with ls first.
💡 Pro Tip
Use cd - to toggle between two directories. It's like Alt+Tab but for the terminal — incredibly useful when working between a project and its docs.
cd & Paths
Practice changing directories with absolute and relative paths.
// cd — Change Directory
console.log("=== cd Basics ===");
console.log("$ cd Documents → Enter Documents folder");
console.log("$ cd .. → Go UP one level (parent)");
console.log("$ cd ../.. → Go UP two levels");
console.log("$ cd ~ → Go to home directory");
console.log("$ cd / → Go to root directory");
console.log("$ cd - → Go to PREVIOUS directory");
console.log();
console.log("=== Path Types ===");
console.log("Absolute pa
...📋 Quick Reference
| Command | Description |
|---|---|
| pwd | Print current directory path |
| ls -la | List all files in long format |
| cd dir | Enter directory |
| cd .. | Go up one level |
| cd ~ | Go to home directory |
| cd - | Go to previous directory |
🎉 Lesson Complete!
You can now navigate the file system like a pro! Next: creating, copying, moving, and deleting files from the command line.
Sign up for free to track which lessons you've completed and get learning reminders.