File System Navigation
Reviewed & published by Brayan K
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.
Part of the free Command Line course at LearnCodingFast — hands-on lessons with worked examples and the output they print, plus practice exercises and a quick quiz.
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
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?
pwd2️⃣ 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.
🔎 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 linkThe 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.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 -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
# /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 2Common Errors (and the fix)
- "No such file or directory" — relative vs absolute confusion. You ran cd projects/webapp but you weren't in /home/user, so the relative path pointed nowhere. Run pwd to see where you actually are, then either move there first or use the full absolute path cd /home/user/projects/webapp.
- "No such file or directory" — a space in the path. cd My Project looks 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 cd into folders. cd notes.txt fails because notes.txt is a file. Run ls -l first and look for a d at the start of the line to confirm it's a directory.
- "command not found: tree". The tree command isn't installed by default everywhere. Install it with sudo apt install tree (Debian/Ubuntu), sudo dnf install tree (Fedora), or brew 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 |
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🎉 Lesson Complete!
- ✅ pwd always tells you which directory you're standing in
- ✅ ls lists files; flags -l -a -h -t stack to control the view
- ✅ cd moves 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 /, and tree draws it
Practice quiz
What does the ls command do?
- Changes directory
- Deletes files
- Lists the contents of a directory
- Prints the current path
Answer: Lists the contents of a directory. ls lists what is inside the current directory.
Which command moves you into a different folder?
- cd
- pwd
- ls
- tree
Answer: cd. cd means change directory.
What does the ls -a flag do?
- Sorts by size
- Shows hidden files starting with a dot
- Sorts by time
- Shows human-readable sizes
Answer: Shows hidden files starting with a dot. -a means all, including hidden dot-files.
What does the ~ (tilde) shortcut refer to?
- The root directory
- The previous directory
- The parent directory
- Your home directory
Answer: Your home directory. ~ is a shortcut for your home directory.
An absolute path always starts with which character?
- A tilde ~
- A dot .
- A forward slash /
- Two dots ..
Answer: A forward slash /. Absolute paths start from the root, written as /.
What does .. mean in a path?
- The parent directory (up one level)
- The current directory
- Your home directory
- The root directory
Answer: The parent directory (up one level). .. means go up one level to the parent.
Which flag makes ls show human-readable sizes like 1.2K?
- -l
- -h
- -t
- -a
Answer: -h. -h gives human-readable sizes (K, M, G).
What does cd - do?
- Goes to root
- Goes home
- Lists directories
- Toggles back to the previous directory
Answer: Toggles back to the previous directory. cd - jumps back to the directory you were just in.
When cd succeeds, what does it print?
- Nothing
- The new path
- An error
- The file list
Answer: Nothing. cd is silent on success; run pwd to confirm where you landed.
What does a single dot . mean in a path?
- Up one level
- Here, the current directory
- Your home directory
- The root
Answer: Here, the current directory. . means the current directory, here.
Continue this course
- Previous: Introduction to the Command Line
- Next: File Management Commands — Create, copy, move, rename, and delete files and folders from the terminal
- Quick reference: Command Line cheat sheet › Navigation · Bash cheat sheet › Navigation & Files
Frequently asked questions
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.
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'.
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.
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'.
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.
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.