The Filesystem Is a Tree

What this is. Every file on the machine lives in exactly one place in a single tree. The tree starts at /, called the root, and everything hangs beneath it.

A path is the address of a place in that tree, written as names separated by slashes.

Two ways to write an address, and the distinction matters constantly.

An absolute path starts at the root, so it begins with /. /home/learner/projects means the same thing no matter where you currently stand.

A relative path starts from wherever you are now. projects means the projects directory inside the current one, so its meaning changes as you move.

Same destination, two addresses

ABSOLUTE

/home/learner/projects/archive

always means this exact place,
from anywhere on the machine

RELATIVE

projects/archive

means this place only when you
are already in /home/learner
Compare → Absolute paths are unambiguous but long. Relative paths are short but depend on where you are, which is why a script that works in one directory can fail in another. When something behaves oddly, pwd is almost always the first thing to check.

Three shorthands you will use every day.

. is the current directory.

.. is the parent, one level up.

~ is your home directory.

So ../map means go up one level then into map, and ~/projects means the projects directory inside your home no matter where you are.

SANKOFA SANDBOX
learner:~$

The tree here: your home holds projects and logs, and projects holds archive and map.

Try it → Run `cd projects/archive`, then `pwd`. Now run `cd ../map` and `pwd` again. Then `cd ~` to get home. Watch the prompt change each time.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Moving and Looking →
← Back