Lesson 2 • Beginner
File System Navigation 🗂️
By the end of this lesson you'll move around your computer entirely from the keyboard — knowing exactly where you are, what's around you, and how to walk to any folder using the three commands you'll reach for hundreds of times a day: pwd, ls, and cd.
What You'll Learn
- Use pwd to know exactly which directory you're in
- List files with ls and the flags -l, -a, -h, and -t
- Move between folders with cd, including subdirectories and parents
- Tell absolute paths (from /) apart from relative paths (from here)
- Use the shortcuts ~, .., ., and cd - to travel fast
- Picture the filesystem as one tree and draw it with tree
pwd reads the sign on the door so you know which room you're standing in. ls looks around and tells you everything in the room. cd walks you through a doorway into another room. An absolute path is the room's full street address (it works from anywhere in the city); a relative path is directions from where you're standing ("go next door, then upstairs"). Folders inside folders are just rooms inside rooms.1️⃣ pwd — Where Am I?
The terminal always has a current directory — the folder your commands act on. Unlike a file explorer, there's no window title constantly showing it, so the first command every developer learns is pwd ("print working directory"). It prints the full path to where you are right now. Run it whenever you feel lost; it never changes anything, so it's completely safe.
# pwd = "print working directory".
# It answers one question: which folder am I standing in right now?
pwd/home/user/projects2️⃣ ls — What's In Here?
ls ("list") shows the contents of the current directory. On its own it gives a plain list, but its real power is in its flags — single letters after a dash that change its behaviour. The four you'll use constantly are -l (long, detailed format), -a (all, including hidden dot-files), -h (human-readable sizes like 1.2K), and -t (sort newest-first). Flags stack, so ls -lah applies all three of the first ones at once.
# ls = "list" — show what is inside the current directory.
ls
# -l long format: one file per line, with details
# -a all: include hidden files (names that start with a dot)
# -h human-readable sizes (K, M, G instead of raw bytes)
# -t sort by time, newest first
# Flags stack, so -lah means "long + all + human sizes".
ls -lah
# Sort newest-first to see what you changed most recently
ls -ltDocuments Downloads notes.txt photo.jpg
total 28K
drwxr-xr-x 4 user user 4.0K Jun 14 09:00 .
drwxr-xr-x 18 user user 4.0K Jun 10 18:22 ..
-rw-r--r-- 1 user user 220 Jun 13 11:05 .bashrc
drwxr-xr-x 5 user user 4.0K Jun 12 08:30 Documents
drwxr-xr-x 2 user user 4.0K Jun 11 14:10 Downloads
-rw-r--r-- 1 user user 1.2K Jun 14 08:59 notes.txt
-rw-r--r-- 1 user user 480K Jun 09 21:44 photo.jpg
total 28K
-rw-r--r-- 1 user user 1.2K Jun 14 08:59 notes.txt
drwxr-xr-x 5 user user 4.0K Jun 12 08:30 Documents
drwxr-xr-x 2 user user 4.0K Jun 11 14:10 Downloads
-rw-r--r-- 1 user user 480K Jun 09 21:44 photo.jpg🔎 Reading an ls -l Line
Each long-format line packs a lot in. From left to right: the type and permissions, link count, owner, group, size, modified date, and finally the name. Here's the same line annotated:
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=symbolic link
The very first character is the quickest tell: d means it's a directory you can cd into, - means it's a regular file, and l means it's a symbolic link (a shortcut to somewhere else).
Your turn. The program below is almost complete — fill in the three blanks marked ___ with the right flag using the hints, then run each line.
# 🎯 YOUR TURN — replace each ___ with the right flag, then run it.
# 1) List EVERY file, including hidden ones starting with a dot
ls ___ # 👉 the flag for "all" is a single letter
# 2) Show a long listing with human-readable sizes
ls ___ # 👉 stack two flags: long + human, e.g. -lh
# 3) List the newest files first (long format)
ls ___ # 👉 stack long + time, e.g. -lt
# ✅ Expected: the first command shows .bashrc and . and ..,
# the second shows sizes like 1.2K / 480K, and the third
# lists notes.txt at the top because it was edited most recently.# After ls -a:
. .. .bashrc Documents Downloads notes.txt photo.jpg
# After ls -lh:
-rw-r--r-- 1 user user 1.2K Jun 14 08:59 notes.txt
-rw-r--r-- 1 user user 480K Jun 09 21:44 photo.jpg
# After ls -lt:
-rw-r--r-- 1 user user 1.2K Jun 14 08:59 notes.txt
drwxr-xr-x 5 user user 4.0K Jun 12 08:30 Documents___, run it in your own terminal, and check your output against the expected results above.3️⃣ cd — Moving Around
cd ("change directory") walks you from one folder to another. You point it at a path, and there are two kinds. An absolute path starts with a leading / (the root) and means the same place from anywhere — like a full address. A relative path starts from wherever you already are. Three symbols make relative paths fast: . is "here", .. is "up one level", and ~ is your home directory. Bonus: cd - toggles back to the directory you were last in.
# cd = "change directory" — walk from one folder to another.
# Absolute path: starts from / (the root). Works from ANYWHERE.
cd /home/user/projects/webapp
# Relative path: starts from where you already are.
# From /home/user/projects, this reaches the same place:
cd webapp
# . means "here" (the current directory)
cd ./src
# .. means "up one level" (the parent directory)
cd .. # back up to webapp
cd ../.. # up two levels at once
# ~ is a shortcut for YOUR home directory (/home/user)
cd ~
# cd with no path also goes home
cd
# cd - jumps back to the directory you were just in (a toggle)
cd -# cd prints nothing when it succeeds — it just moves you.
# Confirm each move with pwd. After the steps above:
/home/user/projects/webapp
/home/user/projects/webapp
/home/user/projects/webapp/src
/home/user/projects/webapp
/home/user/projects
/home/user
/home/user
/home/user/projects # cd - returned you to the previous spotcd prints nothing on success — follow each move with pwd to see where you landed.Pro Tip: cd - is Alt-Tab for the Terminal
cd - jumps you straight back to the previous directory and prints its path. It's perfect when you're bouncing between two folders — say a project and its log directory deep elsewhere. And don't forget Tab completion: type the first few letters of a folder name and press Tab, and the shell fills in the rest (and escapes any awkward characters for you).
Now you try. You're standing in /home/user/projects/webapp/src. Fill in each blank to make the move described, then confirm with pwd.
# 🎯 YOUR TURN — you are standing in /home/user/projects/webapp/src.
# Fill in each ___ to make the move described, then check with pwd.
# 1) Go UP one level (back into webapp)
cd ___ # 👉 two dots means "parent directory"
# 2) From there, jump straight to your HOME directory
cd ___ # 👉 a single tilde character
# 3) Now go to the filesystem ROOT
cd ___ # 👉 a single forward slash
# ✅ Expected (run pwd after each line):
# /home/user/projects/webapp
# /home/user
# //home/user/projects/webapp
/home/user
/___, run it in your own terminal, and run pwd after each line to check.4️⃣ The Filesystem Tree
Every path you've typed is a route through one big structure: the filesystem tree. It starts at a single root, written /, and branches into directories, which branch into more directories and files. A path like /home/user/notes.txt simply spells out the branches you follow from the root. The tree command draws this picture for you, and -L 2 keeps it readable by stopping at two levels deep. (If tree isn't installed, add it with sudo apt install tree on Linux or brew install tree on macOS.)
# The filesystem is one big upside-down tree. It starts at / (the root)
# and branches into directories, which branch into more directories.
# The 'tree' command draws that structure for you.
# Show the tree starting here (-L 2 limits it to 2 levels deep)
tree -L 2.
├── Documents
│ ├── cv.pdf
│ └── notes.txt
├── Downloads
│ └── installer.deb
└── projects
├── webapp
└── api
5 directories, 3 filesCommon Errors (and the fix)
- "No such file or directory" — relative vs absolute confusion. You ran
cd projects/webappbut you weren't in/home/user, so the relative path pointed nowhere. Runpwdto see where you actually are, then either move there first or use the full absolute pathcd /home/user/projects/webapp. - "No such file or directory" — a space in the path.
cd My Projectlooks like two separate arguments to the shell. Quote the name —cd "My Project"— or escape the space with a backslash:cd My\ Project. Pressing Tab to autocomplete does this for you. - "Not a directory" — you tried to cd into a file. You can only
cdinto folders.cd notes.txtfails becausenotes.txtis a file. Runls -lfirst and look for adat the start of the line to confirm it's a directory. - "command not found: tree". The
treecommand isn't installed by default everywhere. Install it withsudo apt install tree(Debian/Ubuntu),sudo dnf install tree(Fedora), orbrew install tree(macOS).
📋 Quick Reference
| Command | What it does |
|---|---|
| pwd | Print the current directory's full path |
| ls -l | Long listing: permissions, size, date, name |
| ls -a | Include hidden files (dot-files) |
| ls -lh | Long listing with human-readable sizes |
| ls -lt | Long listing, newest files first |
| cd dir | Enter a subdirectory (relative path) |
| cd /abs/path | Go to an absolute path (works anywhere) |
| cd .. | Go up one level to the parent |
| cd ~ | Go to your home directory |
| cd - | Toggle back to the previous directory |
| tree -L 2 | Draw the directory tree, 2 levels deep |
Frequently Asked Questions
Q: What is the difference between an absolute and a relative path?
An absolute path starts from the root with a leading slash (for example /home/user/projects) and means the exact same place no matter where you currently are. A relative path starts from your current directory (for example projects/webapp or ../docs) and changes meaning depending on where you run it. Use pwd to see your current location when a relative path is not behaving as you expect.
Q: What do the . and .. symbols mean?
A single dot (.) means the current directory — 'here'. Two dots (..) mean the parent directory — one level up. You can chain them, so ../.. goes up two levels and ./src means 'the src folder inside here'.
Q: What does the ~ (tilde) symbol do?
The tilde is a shortcut for your home directory, usually /home/yourname on Linux or /Users/yourname on macOS. So cd ~ and cd ~/Documents take you home or into your home Documents folder from anywhere. Typing cd with no argument at all also takes you home.
Q: Why did my cd command print nothing?
That is success. cd is silent when it works — it simply moves you. To confirm where you ended up, run pwd. You only see a message from cd when something goes wrong, such as 'No such file or directory' or 'Not a directory'.
Q: How do I cd into a folder that has a space in its name?
The shell treats a space as a separator between arguments, so cd My Project looks like two arguments. Wrap the name in quotes — cd "My Project" — or escape the space with a backslash: cd My\ Project. Tab-completion does this escaping for you automatically.
Q: What is the difference between ls -lt and ls -lS?
Both use -l for the detailed long format. The -t flag sorts by modification time with the newest files first, which is great for spotting what you just changed. The -S flag sorts by size with the largest files first, handy when hunting for what is filling up a directory. Add -r to reverse either order.
Mini-Challenge: Find Your Way Around
No blanks this time — just a brief and an outline to keep you on track. Work through the five steps using only pwd, ls, and cd, then check your terminal against the expected output.
# 🎯 MINI-CHALLENGE: find your way around a fresh project
#
# Starting point: your home directory (~).
#
# 1. Confirm where you are.
# 2. List everything in your home folder, including hidden files,
# with human-readable sizes.
# 3. Move into projects/webapp using a single relative path.
# 4. Confirm you arrived.
# 5. Jump straight back home with one short command (not the full path).
#
# ✅ Hint: you only need pwd, ls (with stacked flags), and cd
# (a relative path, then a shortcut). No absolute paths required.
# your commands here/home/user
total 24K
drwxr-xr-x 6 user user 4.0K Jun 14 09:00 .
-rw-r--r-- 1 user user 220 Jun 13 11:05 .bashrc
drwxr-xr-x 4 user user 4.0K Jun 12 08:30 projects
/home/user/projects/webapp
/home/user🎉 Lesson Complete!
- ✅
pwdalways tells you which directory you're standing in - ✅
lslists files; flags-l -a -h -tstack to control the view - ✅
cdmoves you; absolute paths start with/, relative paths start from here - ✅
.= here,..= up one level,~= home,cd -= toggle back - ✅ The filesystem is one tree rooted at
/, andtreedraws it - ✅ Next lesson: File Management — create, copy, move, and delete files from the command line
Sign up for free to track which lessons you've completed and get learning reminders.