LearnLinux FoundationsNavigation

Dot Directories (. and ..)

cd - a hands-on Linux lab on a real virtual machine.

Every directory holds two special entries: . (here) and .. (the parent). Climb the tree with cd .., reach siblings with ../name, and run local programs with ./ on the recon-base filesystem.

Back on recon-base. Pick any folder on the machine, even a small one you think you know the whole contents of, and Linux has quietly slipped two extra entries inside it that you never put there.

See for yourself. The contingency plan plan-charlie holds two files. List every single thing inside it, hidden items and all. The path is ~/recon-base/ops/plan-charlie.

The black boxes below are a practice terminal: a safe sandbox that only checks the one command each step teaches. You cannot break anything. The real machine, where you run the full mission, is the lab at the very end.

The ~ is a shortcut that means "my home folder," which on this machine is /home/student. A directory is just Linux's word for a folder. Type this exact command:

ls -a ~/recon-base/ops/plan-charlie

prompt: student@linuxcamp:~$ answer: ls -a ~/recon-base/ops/plan-charlie output: . .. contingency.txt objectives.txt hint: ls lists names, -a shows hidden ones too. Type: ls -a ~/recon-base/ops/plan-charlie

You expected two files, contingency.txt and objectives.txt. But ls -a turned up four entries. The two extras at the front are . and ...

You did not create them. Linux did, the instant plan-charlie was made. Every directory on the system is born with exactly these two, no matter what else is inside it. They are the subject of this whole lesson.

Here is plan-charlie drawn out, exactly as ls -a just showed it. The two dots are not floating outside the folder; they sit INSIDE it, right alongside the two files. Click each highlighted entry to see what it points at.

{ "caption": "The first two entries, . and .., live inside plan-charlie itself, next to the two files.", "highlight": [ "/home/student/recon-base/ops/plan-charlie/.", "/home/student/recon-base/ops/plan-charlie/.." ], "annotations": { "/home/student/recon-base/ops/plan-charlie/.": { "tag": "this folder", "note": "The single dot . is plan-charlie itself. That is why ./run-scan.sh means the copy right here, and ls . lists this very folder." }, "/home/student/recon-base/ops/plan-charlie/..": { "tag": "parent: ops", "note": "The double dot .. is the folder one level up, ops. That is why cd .. climbs out of plan-charlie into ops." } }, "tree": { "name": "/", "children": [{ "name": "home", "children": [{ "name": "student", "children": [{ "name": "recon-base", "children": [{ "name": "ops", "children": [{ "name": "plan-charlie", "children": [ { "name": "." }, { "name": ".." }, { "name": "contingency.txt" }, { "name": "objectives.txt" } ] }] }] }] }] }] } }

You saw them in the ls lesson too, at the front of every ls -a. Here is what they actually are:

Think of a building. . is the floor you are standing on. .. is the stairwell up to the floor above. They are not files someone left behind. They are the built-in links that hold the whole folder tree together, so the system can always find its way up and down.

Because . and .. live in every directory, the two commands ls -a and cd .. work the same way absolutely everywhere on Linux. Learn them once, use them for life.

To use .., you first need to know where you are. The command for that is pwd, which stands for "print working directory." Your working directory is simply the folder your terminal is sitting in right now.

For this lesson, imagine you have already moved deep into the operation plans, into plan-alpha. Confirm the spot. Type:

pwd

prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: pwd output: /home/student/recon-base/ops/plan-alpha hint: Just three letters, no path. Type: pwd

There is your full address: /home/student/recon-base/ops/plan-alpha. You are four levels deep inside your home folder. Keep that path in mind. In the next step you are going to climb out of it one floor at a time.

The command that moves you between directories is cd, short for "change directory." You point it at a destination and your terminal walks there.

Give it .. as the destination and it walks to the parent, one level up. From plan-alpha, the parent is ops. Run it:

cd ..

prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: cd .. output: hint: cd changes directory, .. means the parent. Type: cd ..

Nothing printed. That blank line is cd quietly telling you it worked. On Linux, silence means success. cd never announces where it took you; it just takes you there.

Since cd said nothing, confirm the move the same way you always do: ask pwd where you are now.

pwd

prompt: student@linuxcamp:~/recon-base/ops$ answer: pwd output: /home/student/recon-base/ops hint: The same three letters as before: pwd

There it is: /home/student/recon-base/ops. The plan-alpha on the end is gone. One .. peeled off exactly one level, and you are now standing in ops, the parent.

Here is the part most beginners miss: . and .. are not just for cd. You can drop them into any path, with any command.

Say you are back down in plan-alpha and you want to see what is in its parent, ops, without leaving. Point ls at .. and it lists one level up:

ls ..

prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: ls .. output: plan-alpha plan-bravo plan-charlie run-scan.sh hint: ls takes a path, and .. is a path meaning the parent. Type: ls ..

That is the contents of ops, seen from inside plan-alpha without moving an inch. Three plan folders and a script named run-scan.sh. You can list, read, or copy things in the folder above you just by aiming a command at ...

Now combine the pieces. From inside plan-alpha, you want to peek at what the neighbor plan, plan-bravo, is holding. They are siblings: two folders sharing the same parent, ops.

The route is: go up to the shared parent with .., then straight back down into the sibling. You write that whole trip as one path, ../plan-bravo. Read it left to right as "up one, then into plan-bravo."

ls ../plan-bravo

prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: ls ../plan-bravo output: objectives.txt resources.txt hint: Up one level, then into the neighbor: ls ../plan-bravo

There is plan-bravo, opened from next door: objectives.txt and resources.txt. You never left plan-alpha. The .. climbed to the shared parent and the /plan-bravo dropped back down into the sibling, all in one short path. This is how people move sideways across a filesystem without typing the full address every time.

One .. goes up one floor. Stack another with a slash between them and you go up two: ../.. reads as "up, then up again."

You are back in plan-alpha. Going up two levels means plan-alpha to ops to recon-base. Make the climb:

cd ../..

prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: cd ../.. output: hint: Each .. is one level, joined by a slash. Two levels up is: cd ../..

Silent again, as cd always is. Two floors in one command: the first .. took you from plan-alpha up to ops, the second took you from ops up to recon-base.

Ask pwd to prove where those two dots dropped you.

pwd

prompt: student@linuxcamp:~/recon-base$ answer: pwd output: /home/student/recon-base hint: One more pwd to read the full address: pwd

You are standing in /home/student/recon-base, two floors above where you started. Add a third .., making cd ../../.., and you would climb one level higher again, into your home folder. Each .. is one floor.

You have used .. a lot. Now the single dot, ., which means "this exact directory."

Its most important job is running programs. When you type a plain command name, Linux searches a fixed list of standard system folders for it. That list does not include the folder you are standing in. So a program sitting right next to you stays invisible unless you say exactly where it is.

Recon-base has a script at ~/recon-base/ops/run-scan.sh. Say you are inside ops and type just run-scan.sh. Linux checks its standard folders, does not find the script there, and reports that the command was not found. To run the copy right here, point at it with ./ in front.

./run-scan.sh

That ./ means "the one in this directory, not somewhere on the system." That is the whole reason local scripts are launched as ./name and not a bare name.

There is no practice box for this one; the script waits for you on the real machine. After your sweep there, stand inside ops and try ./run-scan.sh yourself. For now, just hold the idea: ./ means run the copy sitting right where I am standing.

Scaffolding off. No command is shown this time. You know the pieces.

You are back inside ~/recon-base/ops/plan-alpha. Without moving out of it, list the contents of the sibling plan plan-charlie next door. Build the path from .. and the neighbor's name.

prompt: student@linuxcamp:~/recon-base/ops/plan-alpha$ answer: ls ../plan-charlie output: contingency.txt objectives.txt hint: Same shape you used for plan-bravo: up one level, then into the neighbor.

Cracked it. ../plan-charlie climbed to ops and dropped into the third plan: contingency.txt and objectives.txt. You just navigated sideways across the filesystem from memory, no full path, no leaving your folder.

You earned this. Every row is something you ran in the last few minutes:

Two tiny entries, . and .., live in every directory on Linux. Between them they handle a huge share of everyday navigation: going up, reaching across, and running what is right in front of you.

If one thing sticks, make it this: .. is up, . is here. Say it out loud once. You will reach for both dozens of times a day.

The sandbox checked one command at a time. The real machine will not hold your hand.

You will put all of this together in the Navigation mission lab, the one capstone at the end of this module. There you boot the real recon-base on a live Linux VM and move through it for real. You climb with .., reach across to siblings with ../name, and confirm every landing with pwd. The script is there too: once your sweep is done, stand inside ops and fire ./run-scan.sh for the satisfaction of it. No commands are shown in the objectives. You read, you recall the dots, you type. That recall is what makes it stick.

Practice Dot Directories (. and ..) in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.