Absolute, relative, and remembered paths
Use path forms intentionally instead of wandering the tree.
cd -
20 min read, 20 min lab
beginner
An absolute path starts at `/`. A relative path starts from the current directory. `.` is here, `..` is parent, `~` is home, and `cd -` returns to the previous directory. These are navigation controls, not trivia.
You need to compare a config under `/etc` with logs under `/var/log` without losing your working location.
Worked command
$ pwd/home/studio-dev$ cd /etc/ssh$ cd /var/log$ cd -/etc/ssh$ realpath ../systemd
Do not use a relative path when you are not certain of the current directory.
Use `pwd` before broad commands and absolute paths for high-consequence targets.
You run a destructive command against `../tmp` instead of `/tmp`. Compared to `/tmp`, what makes the relative form riskier?
Show the answer
Correct: B. Its target depends on your current directory, which you may have wrong
`../tmp` resolves against whatever directory you currently stand in, so a wrong assumption about the cwd aims the command at the wrong target; `/tmp` is fixed no matter where you are. The relative form does not 'always' sit above home — that holds only for one specific cwd.
Practice checklist
- Create `/tmp/td-nav/a/b/c`.
- Navigate using one absolute path and two relative paths.
- Use `cd -` to return to the previous directory.
Deliverable evidence
- A command transcript showing absolute and relative movement.
- One sentence explaining `.` and `..`.
shows: How `.`, `..`, and `~` resolve from the current directory into a single absolute location, with `pwd`/`realpath` confirming where you actually are and `find` filtering a tree down to evidence.
does not prove: It shows how path tokens resolve in principle; it does not prove your shell's current directory at any moment — only running `pwd` or `realpath` on the live machine proves that.
Commit these to memory, then drill them until recall is automatic.
cue You changed directories twice and want to jump straight back to the directory you were in before this one.
show recall target
cd -