Navigation and Paths
Where am I, what is here, and how paths actually resolve.
- Use pwd, ls, cd and interpret absolute vs relative paths
- Create and remove directories safely (mkdir -p, rmdir, rm -r care)
- Read ls flags and predict what a command will touch before running it
Every server, CI runner and cloud VM assumes you can drive a shell. The filesystem tree is the same shape on your laptop, a lab Linux box and a production container — once navigation is muscle memory, everything else is vocabulary.
Where you are: pwd prints the working directory. Everything relative resolves from there.
Absolute vs relative:
- Absolute starts at / (root): /home/you/notes.txt
- Relative starts from cwd: notes.txt or ../shared/todo.md
- ~ expands to your home directory; . is here; .. is parent.
Listing: ls, ls -l (long), ls -a (hidden), ls -lah (human sizes). Colour output means: blue directory, green executable, cyan symlink.
Changing directory: cd /var/log, cd .., cd - (previous), cd (home).
Create / remove:
- mkdir -p a/b/c — parents as needed, no error if exists.
- rmdir empty_dir — only if empty.
- rm -r dir — recursive; rm -rf is powerful and irreversible. Prefer trash or explicit paths. Never rm -rf / or unquoted variables that might be empty.
Read before you destroy: ls the target; echo "$VAR" before rm -rf "$VAR".
| Token | Resolves to |
|---|---|
| / | Root of the filesystem |
| . | Current directory |
| .. | Parent directory |
| ~ | Your home directory |
| - | Previous working directory (cd -) |
Escaping paths by hand is how people delete the wrong tree. Tab until the path is unambiguous.
Can wipe the wrong directory instantly. Quote variables; dry-run with echo first.
- 1
Step 1 - orient
pwd && ls ~ to orient.
- 2
Step 2 - enter project
cd ~/projects/demo && ls -la.
- 3
Step 3 - inspect log
cd logs && ls -lh app.log.
- 4
Step 4 - jump back
cd - to jump back to the previous directory.
- 5
Step 5 - home
cd .. repeatedly until home; verify with pwd.
Solution
You can move deliberately and prove where you are at every step.
From /home/you/src, what does ../notes/../notes/../notes.txt resolve to? Write it out.
Hint: Resolve one .. at a time from left to right.
rm -rf on a relative path while in the wrong directory
pwd first; prefer absolute paths for destructive commands.
Ignoring -a and thinking a directory is empty
Hidden files start with .; ls -a shows them.
What do . and .. mean in a path?
. is the current directory; .. is its parent.
Source: Most common Linux viva.
- Absolute paths start at /; relative paths start at cwd.
- pwd/ls/cd are your map; tab-complete everything.
- Recursive delete is irreversible — prove the target first.