Quiz
Warm-up from lesson 1-2: what does pwd print?
Absolute vs relative paths
Everything on Linux names files by path: error messages (No such file or directory), configuration files, scripts, and every command that takes a file argument. A large share of beginner debugging ends with "the command was given the wrong path", so learn the addressing rules once, properly.
A path is the address of a file or directory. There are exactly two kinds:
- Absolute path: starts with
/(the root) and spells out the whole route, like/home/sam/projects/notes.txt. It means the same thing no matter where you are standing. - Relative path: starts from your current working directory, like
projects/notes.txt. Its meaning changes as you move around.
Two special names work inside any path:
.means the current directory..means the parent directory (one level up)
So cd .. moves up one level, and cd ../.. moves up two.
Code exercise · bash
Run it. We build a nested tree, dive in with one relative path, then climb out with .. The `basename` command shows just the last part of pwd's answer, so you can see each hop.
Quiz
Which of these is a relative path?
Code exercise · bash
Your turn. Create the nested directory `garden/roses` in one command, cd into it, print its name with `basename "$(pwd)"`, then go up one level with .. and print that directory's name too. Expected output: ``` roses garden ```