That's a great question! Understanding the difference between these two path types is key to navigating Linux efficiently.
1. Absolute Paths
An absolute path is the full address of a file or directory, starting from the very top of the system (the root /).
- Always starts with:
/ - Analogy: Like a full mailing address including Country, State, City, and Street. No matter where you are, it always points to the same spot.
- Example from this lab:
/tmp/hello- It starts at root (
/), goes intotmp, then findshello.
- It starts at root (
2. Relative Paths
A relative path points to a file or directory relative to where you are currently "standing" (your Current Working Directory).
- Does NOT start with:
/ - Analogy: Like giving directions from your current spot: "Go two doors down on the left."
- Example:
If you are currently in the/home/labexfolder and you want to access a folder namedproject:- Relative Path:
project - Absolute Path:
/home/labex/project
- Relative Path:
Key Comparison
| Feature | Absolute Path | Relative Path |
|---|---|---|
| Starts with | / (Root) |
Name of a file/folder or . or .. |
| Depends on location? | No | Yes |
| Use case | When you want to be precise regardless of where you are. | When you are already working inside a folder and want to access things nearby. |
Pro Tip: In the terminal, you can type pwd (Print Working Directory) at any time to see your current absolute path!
Do you want to try moving between directories to see how relative paths change?