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 .
Part of the free Cli course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
What You'll Learn
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.
2️⃣ 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:
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.
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.
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 .
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.)
Common 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
Frequently Asked Questions
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.
🎉 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
- ✅ Next lesson: File Management — create, copy, move, and delete files from the command line
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