Navigating the Linux Filesystem
The question: what will this path name from here?
Section titled “The question: what will this path name from here?”The same relative path can point at completely different things depending on where you happen to be standing.
Linux lays out files and directories as a single hierarchy. At the very top sits the root directory, written /. Every ordinary absolute path starts there and works its way down through a sequence of names. Your home directory is one branch of that tree assigned to your user. The shell also remembers a current working directory, and that’s the starting point every relative path is measured from.
So think of a path as directions rather than as a name. /home/student/notes.txt says “start at root, go into home, go into student, then look for notes.txt.” Plain notes.txt says “look for that name right here.” The street-directions analogy is useful, and it has one limit worth knowing early. .. isn’t text substitution. The system resolves each component against the directory it has reached so far.
So let’s start by working out where you currently are:
pwdYour username will be different, but the result should have this shape:
/home/studentA leading / means the path starts at the filesystem root, ~ is shell shorthand for your home directory, . means the current directory, and .. means the parent of the current directory.
The shell expands ~ before the command sees the argument. The filesystem uses / to separate path components and gives . and .. their current-directory and parent-directory meanings during path resolution. That separation matters quite a bit. An error can come from shell expansion, from the starting directory, or from a component that simply isn’t there (three different problems, three different fixes).
Build one stable practice tree
Section titled “Build one stable practice tree”Run this setup exactly:
mkdir -p ~/underdunn-course/exercises/navigation/evidence/rawmkdir -p ~/underdunn-course/exercises/navigation/reportstouch ~/underdunn-course/exercises/navigation/evidence/notes.txttouch ~/underdunn-course/exercises/navigation/reports/summary.txtcd ~/underdunn-course/exercises/navigationVerify the starting state:
pwdlsExpected evidence, with your username substituted in the path:
/home/student/underdunn-course/exercises/navigationevidence reportsThe real directory tree is:
navigation/├── evidence/│ ├── notes.txt│ └── raw/└── reports/ └── summary.txtPredict relative paths
Section titled “Predict relative paths”From navigation, predict the pwd result before each move. Write them all down first, because a prediction made after the output appears isn’t really a prediction:
cd evidencepwdcd rawpwdcd ../..pwdThat last command moves from raw up to evidence, and then from evidence up to navigation.
So the observation is that .. gets interpreted from wherever you are at that exact moment. And the conclusion is narrower than it sounds. A relative path is only half a location, and it needs a known starting directory to mean anything.
navigation/evidence/rawwhere cd ../.. startsnavigation/evidenceafter the first ..navigationafter the second ..Linux resolves a path from left to right, one piece at a time. That’s why a wrong component fails where it sits, instead of quietly resolving to something else further along. When a path fails, check its starting directory and each component in order.
Compare absolute and relative names
Section titled “Compare absolute and relative names”Return to the stable start:
cd ~/underdunn-course/exercises/navigationThese commands name the same directory:
ls evidencels ~/underdunn-course/exercises/navigation/evidenceThe first is relative to wherever you currently are. The second expands ~ and then follows a path anchored in your home directory, so it means the same thing from anywhere.
Change one variable by moving to reports:
cd reportsPredict which of those two commands still works unchanged, and then test both. The home-based path still names the same location. The relative evidence now looks inside reports instead, and should fail.
Compare that error with the earlier successful command. The path text never changed; only your starting location did.
Coreutils directory operations documents the listing options used here. Compare a listing with pwd before deciding that a file disappeared.
Spaces and hidden names
Section titled “Spaces and hidden names”Return to the stable start and create two names:
cd ~/underdunn-course/exercises/navigationtouch "field notes.txt" .checkpointlsls -aThe ordinary listing shows field notes.txt but not .checkpoint. The -a listing shows both. The quotes kept the space inside one argument, and the quote characters themselves are not part of the filename.
A leading dot doesn’t give a file some special hidden attribute (this surprises people coming from other systems). Most Unix tools usually leave dot-prefixed names out of an ordinary listing, and -a is what asks ls to include them anyway. The entry exists either way, and you can always name it directly, whether or not the default listing bothers to show it.
Predict the argument you’d need to list only the spaced name, and then check:
ls "field notes.txt"Practice without a transcript
Section titled “Practice without a transcript”Starting from navigation/reports:
- Predict a relative path to
evidence/notes.txt. - List that file without leaving
reports. - Move to
evidence/rawusing a relative path. - Print the absolute current directory.
- List the parent directory without leaving
raw.
Check each prediction and each result before you move on to the next step.
Common failures and recovery
Section titled “Common failures and recovery”No such file or directory: runpwdfirst, then read the relative path again starting from what it printed.- A path with spaces produces two errors instead of one: quote the whole path, not just part of it.
- Names seem to be missing: use
ls -awhenever the question involves entries that begin with a.. - You’ve completely lost track of where you are: get back with
cd ~/underdunn-course/exercises/navigationand confirm it withpwd. This happens to everybody. - The practice tree is wrecked: confirm you’re inside
~/underdunn-course/exercises, remove only thenavigationdirectory, and run the setup block again. I’d recommend checkingpwdtwice before you remove anything.
Check your result
Section titled “Check your result”Compare pwd after the absolute and relative moves. The absolute path starts at /; the relative path starts in your current directory. If you arrived somewhere unexpected, walk through each .. from that starting directory.