Learn › Linux Foundations › Navigation
cd - a hands-on Linux lab on a real virtual machine.
Navigate recon-base both ways: absolute paths that work from anywhere and relative paths read from where you stand. Confirm every landing with pwd, right in the practice terminal.
You are back on recon-base, the same box you mapped with ls. This time the mission is not to look. It is to move.
Here is the puzzle. There is a folder deep inside the base called plan-alpha. There are two completely different ways to name where it is, and both are correct. One works from anywhere on the whole machine. The other only works from where you happen to be standing right now.
By the end of this lesson you will walk to that folder both ways, and a single command will confirm you landed in the exact same spot each time.
The black boxes in this lesson are a practice terminal. It is a safe sandbox that only checks the one command each step teaches, so you cannot break anything. At the end you launch a real Linux machine and run the full mission there.
Before you can move, you need to know where you are standing. On Linux, the folder your terminal is currently sitting inside is called your current directory. A directory is just Linux's word for a folder. The two mean the same thing.
The command pwd prints your current directory. The name is short for "print working directory", and "working directory" is another name for the current one.
You have not moved yet, so you are sitting in your home directory: the personal folder that belongs to you. Type this exact command in the practice terminal and press Enter:
pwd
prompt: student@linuxcamp:~$ answer: pwd output: /home/student hint: Just three letters, then press Enter: pwd
/home/student is your home directory. Look at the prompt itself: student@linuxcamp:~$. That little ~ is Linux telling you the same thing in shorthand. You are home. pwd just spelled it out in full.
A path is the address of a file or folder. There are two kinds, and this is the whole lesson.
An absolute path starts with a single /, which is the very top of the machine, called the root. Everything on Linux lives somewhere under root. An absolute path spells out the complete route from the top down, so it names one exact place and works no matter where you are standing.
The command that moves you is cd, short for "change directory." Give it an absolute path to walk straight into recon-base from anywhere:
cd /home/student/recon-base
prompt: student@linuxcamp:~$ answer: cd /home/student/recon-base output: hint: Type cd, a space, then the full address starting at the root slash: cd /home/student/recon-base
cd prints nothing when it works. Silence is success here. That blank line is Linux quietly telling you it moved.
Since cd says nothing, you confirm the move the same way you started: ask pwd where you are now.
pwd
prompt: student@linuxcamp:~/recon-base$ answer: pwd output: /home/student/recon-base hint: Same three letters as before: pwd
You moved. The prompt changed too: it now reads ~/recon-base, showing your new spot relative to home. That absolute path, /home/student/recon-base, would have landed you here from literally anywhere on the machine, because it starts at the root and leaves nothing to guess.
Now the second road. A relative path does not start with /. It is read from your current directory, wherever that happens to be. It is directions from here, not a full address.
You are standing in /home/student/recon-base. Inside it is ops, and inside that is plan-alpha. Instead of typing the whole address again, name just the part below you:
cd ops/plan-alpha
prompt: student@linuxcamp:~/recon-base$ answer: cd ops/plan-alpha output: hint: No leading slash this time. Name only the folders below you: cd ops/plan-alpha
No slash at the front, so Linux read ops/plan-alpha as directions from where you stood. Same cd command, but this time a relative path did the work in a fraction of the typing.
Here is the payoff the lesson promised. You reached plan-alpha by stepping down with a relative path. Ask pwd for the full, absolute address of where you ended up:
pwd
prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: pwd output: /home/student/recon-base/ops/plan-alpha hint: One more pwd to see the full address: pwd
There it is. The short relative hop cd ops/plan-alpha put you at /home/student/recon-base/ops/plan-alpha, the exact absolute address you could have typed in full from anywhere. Two different roads, one identical door. That is the core idea: every place has both a relative name and an absolute one.
Now play with it. Below is the recon-base tree you have been walking. Click a folder to stand in it, then click any folder or file to target it, and watch both paths compute. Here is the trick to notice: move only where you stand. The absolute path never budges, while the relative one rewrites itself.
{ "caption": "Blue = where you stand. Green = your target. The numbered amber hops ARE the relative path: read them in order.", "home": "/home/student", "current": "/home/student/recon-base/ops/plan-bravo", "target": "/home/student/recon-base/ops/plan-alpha", "tree": { "name": "/", "children": [ { "name": "home", "children": [ { "name": "student", "children": [ { "name": "recon-base", "children": [ { "name": "documents", "children": [ { "name": "mission-brief.txt" }, { "name": "roster.txt" } ] }, { "name": "intel", "children": [ { "name": "coordinates.csv" } ] }, { "name": "logs", "children": [ { "name": "access.log" } ] }, { "name": "ops", "children": [ { "name": "plan-alpha", "children": [ { "name": "objectives.txt" }, { "name": "timeline.txt" } ] }, { "name": "plan-bravo", "children": [ { "name": "objectives.txt" } ] }, { "name": "plan-charlie", "children": [ { "name": "objectives.txt" } ] } ] } ] } ] } ] } ] } }
Reach for a relative path when your target is close to where you already are. Reach for an absolute path when you are jumping somewhere far away, or when you need it to work no matter where you start.
One more tool and you have the full set. The ~ character, called the tilde, is shorthand for your home directory. On this machine ~ always means /home/student, so ~ and the full home path are interchangeable.
You are still down in plan-alpha. To jump all the way back home, you do not need to type the whole address. Just point cd at the tilde:
cd ~
prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: cd ~ output: hint: The tilde is the key just left of Enter on most keyboards: cd ~
Silent success again, and the prompt snapped back to a bare ~. You are home.
Because ~ stands for /home/student, it acts like an absolute path: it always resolves to the same place, so cd ~ gets you home from anywhere. It is just far less to type than the full route.
One last check to close the loop. You started this lesson at home, walked two different roads to plan-alpha, and jumped back with the tilde. Ask pwd to prove you are exactly where you began:
pwd
prompt: student@linuxcamp:~$ answer: pwd output: /home/student hint: The same pwd you have used all lesson: pwd
/home/student, right back where you started. You now have every piece: pwd to see where you are, an absolute path to name a place fully, a relative path to move quickly from here, and ~ as the shortcut home.
Time to take the training wheels off. For these last three moves you get the goal, not the command. You know everything you need.
You are standing in your home directory. Somewhere under recon-base, inside ops, sits a folder called plan-charlie. Your goal: land inside plan-charlie in a single move that would work from anywhere on the machine. You know which kind of path that takes, and you know where it starts.
prompt: student@linuxcamp:~$ answer: cd /home/student/recon-base/ops/plan-charlie output: hint: One move command, one full address. Start at the root slash and spell out every folder on the way down to plan-charlie.
Silence, so it worked. One command, one full address from the root, and you crossed the entire base in a single hop. That is the point of absolute: it did not matter where you started.
You are deep in plan-charlie now, three folders under recon-base. Your goal: get back to your home directory without typing a single folder name.
prompt: student@linuxcamp:~/recon-base/ops/plan-charlie$ answer: cd ~ output: hint: The shortcut character that stands for your home directory is all you need after the move command.
The prompt reads a bare ~ again. Two keystrokes after the move command, and you covered the same distance as typing out /home/student in full.
Last one. From home, your goal is the intel folder inside recon-base. One command, and this time take the short road: no leading slash, just directions from where you stand.
prompt: student@linuxcamp:~$ answer: cd recon-base/intel output: hint: Name only the folders below you, joined by a slash, with nothing in front of the first one.
No slash at the front, so Linux read your directions from home: down into recon-base, then into intel. If you ran pwd right now it would print /home/student/recon-base/intel, the absolute name of the door your relative directions found. All three moves, absolute, shortcut, and relative, came from your own recall.
You earned this cheat sheet. Every row is something you just did on recon-base:
The one rule that tells the two path types apart: if it starts with /, it is absolute. Anything else is relative. Absolute names a place fully and works from anywhere. Relative is directions from your current spot.
When a relative path surprises you and lands you somewhere unexpected, the fix is almost always the same: run pwd first to see where you actually are, then read your path from there.
You just walked recon-base four ways in the practice terminal: pwd to see where you stand, an absolute path from the root, a relative path from here, and ~ to snap home. Every one of those you typed yourself, and the last three you recalled with no command shown.
This module has one real Linux machine waiting for all of it: the Navigation mission lab. There you will run these exact moves for real, on a live recon-base, alongside the other navigation skills. The mission shows no commands. You read each objective, recall the path, and type it, exactly the recall you just practiced here.
Two roads, one base. Ready to practice? When you reach the Navigation mission, you will walk them for real.
Practice Absolute vs Relative Paths in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.