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 .
Learn Python, JavaScript, Java and more with free interactive lessons, real projects and AI-powered help. Beginner-friendly.
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.
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.
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.
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.)
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.
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.