1 / 2 · Book 19 · The Linux Directory Structure · drill: interview Q&A⊞ allnext →Get the book →
1.5Understanding Paths
Absolute vs. Relative Paths
There are two ways to refer to any file or directory:
# Absolute path: starts from root (/)
# Unambiguous -- works no matter what your current directory is
/home/qa/projects/webapp/tests/login.spec.ts
# Relative path: relative to current directory
# Shorter, but depends on where you are
tests/login.spec.ts # If you are in /home/qa/projects/webapp/
../webapp/tests/login.spec.ts # If you are in /home/qa/projects/api/
Special Path Symbols
| Symbol | Meaning | Example |
|---|---|---|
/ |
Root directory | cd / |
~ |
Home directory | cd ~/projects |
. |
Current directory | cp ./config.json /tmp/ |
.. |
Parent directory | cd .. |
- |
Previous directory | cd - |
Pro Tip: In scripts, always use absolute paths. Relative paths break when the script is executed from a different working directory.