Overview
To refer to any file or directory, you use a path. Linux has two kinds — absolute and relative — and understanding the difference is essential to navigating reliably and avoiding mistakes. This lesson explains paths and the special path shortcuts.
Learning objectives
- Distinguish absolute from relative paths.
- Use the
.,..,~, and/path elements. - Choose the right path type for a task.
Core concept
A path specifies a location in the filesystem tree:
- Absolute path — starts from the root
/and gives the full location, e.g./home/alice/notes.txt. It is unambiguous regardless of where you currently are. - Relative path — starts from your current directory, e.g.
notes.txtor../projects/file.txt.
Special elements:
.— the current directory...— the parent directory (one level up).~— the current user's home directory./— the root directory (when leading) or a separator between names.
How it works
An absolute path always points to the same place because it is anchored at /. A relative path depends on your current working directory (pwd), so the same relative path can mean different files depending on where you run it. .. lets you move up the tree (cd ..), . refers to where you are (useful as ./script.sh to run a script in the current directory), and ~ jumps to your home. Choosing absolute vs relative is about clarity and context.
Practical example
From /home/alice:
cat notes.txt(relative) reads/home/alice/notes.txt.cat ../bob/file.txtgoes up to/home, then intobob.cat /etc/hosts(absolute) reads that exact file no matter where you are.cd ~returns to/home/alicefrom anywhere.
Run the same relative cat notes.txt from a different directory and it would look for a different file.
Cybersecurity relevance
Precise path handling matters in security contexts. Scripts should often use absolute paths so they behave consistently regardless of the working directory, avoiding subtle bugs and security issues. Running programs from the current directory (./program) rather than relying on the search path is a deliberate, safer practice. Path confusion also underlies certain vulnerabilities (e.g. relative-path or search-path manipulation), so understanding paths is both a navigation and a security skill.
Common mistakes
- Assuming a relative path always points to the same file — it depends on the current directory.
- Forgetting
./when running a local program, so the shell may not find it. - Mixing up
.(here) and..(up one level).
Key takeaways
- Absolute paths start at
/and are unambiguous; relative paths start from the current directory and depend on where you are. - Shortcuts:
.(current directory),..(parent),~(home),/(root or separator). - Use absolute paths for consistency (especially in scripts), and understand paths both to navigate reliably and to reason about path-related security issues.
Check your understanding
- What is the difference between an absolute and a relative path, and why can the same relative path point to different files?
- What do
.and..each refer to in a path?

