What is the difference between an absolute path and a relative path?
An absolute path starts at the root / and works from anywhere; a relative path starts from wherever you currently are.
* Standing in labstudent, the same file is reached by an absolute path from / or a relative path through ... *
The single giveaway is the leading slash. If a path begins with /, the shell reads it from the top of the tree — unambiguous, location-independent. If it doesn't, the shell silently glues it onto your current directory, so the same text means different files depending on where you're standing.
| Type | Begins with | Example |
|---|---|---|
| Absolute | / |
/home/labstudent/file |
| Relative | a name, ., or .. |
../labadmin/file |
Three special references make relative paths powerful:
.— the current directory..— the parent directory (one level up)~— your home directory
Same target, two ways, standing in /home/labstudent:
cat /home/labadmin/file # absolute: works from anywhere
cat ../labadmin/file # relative: go up to /home, then into labadmin
When to use which: reach for absolute paths in scripts and config files, where you can't predict the working directory and a wrong guess is a bug. Reach for relative paths when typing interactively near your target — they're shorter and faster. The trade-off is robustness vs. brevity.