Table of Contents
Every file and directory in Linux has a path — a unique way to describe where it lives in the filesystem.
There are two main types of paths: absolute paths and relative paths.
Understanding these concepts is fundamental when working in the terminal, writing scripts, or managing Linux servers.
Absolute vs Relative Path in Linux — how directory navigation changes based on your current location
What Is a Path?
A path tells Linux where a file or directory is located in the filesystem.
For example, if you have a file called report.txt inside /home/mike/docs, its full location (or path) is:
/home/mike/docs/report.txt
Absolute Path
An absolute path always starts from the root directory / — the top of the Linux filesystem.
No matter where you are, an absolute path points to the exact same location.
Example
cd /home/mike/docs
This command moves you directly into the /home/mike/docs directory, regardless of your current location.
Key Characteristics
✅ Always starts with /
✅ Works from any location
⚙️ Longer to type but more reliable
Example Use Cases
- Writing shell scripts or cron jobs
- Creating system configuration files
- Running commands in automation tools (Ansible, Terraform, Jenkins, etc.)
Relative Path
A relative path starts from your current working directory rather than the root. It’s shorter to type, but it depends on your current location in the filesystem.
Example
Let’s say you’re in /home/mike:
pwd
/home/mike
Now, to move into the docs directory:
cd docs
That’s a relative path — it works because docs is inside your current directory.
Key Characteristics
✅ Starts from your current directory ✅ Quicker to type ⚠️ May break if the directory structure or your working directory changes
Example Use Cases
- Fast navigation in the terminal
- Lightweight scripts with controlled environments
- Interactive or temporary commands
Key Differences
| Feature | Absolute Path | Relative Path |
|---|---|---|
Starts with / |
✅ Yes | ❌ No |
| Depends on current directory | ❌ No | ✅ Yes |
| Works from any location | ✅ Yes | ❌ No |
| Easier to type | ❌ Longer | ✅ Shorter |
| Breaks if directory changes | ❌ No | ✅ Yes |
| Common use | Scripts, automation, configs | Manual navigation, quick commands |
Practical Examples
Navigating Directories
# Absolute path
cd /home/mike/docs
# Relative path (if you’re already in /home/mike)
cd docs
Copying Files
# Absolute path
cp /home/mike/docs/report.txt /tmp/
# Relative path
cp docs/report.txt /tmp/
TL;DR
Absolute Path — Always starts with
/, works anywhere, reliable. Relative Path — Starts from where you are, shorter, but can break easily.
Final Thoughts
Both absolute and relative paths are essential tools for any Linux user. Use absolute paths in automation, scripts, and production systems. Use relative paths for quick manual work in your terminal.
💡 Pro Tip:
Use pwd (print working directory) to confirm your current location before using relative paths — it helps prevent “No such file or directory” errors.
Start the conversation