Master Linux Paths: Absolute vs Relative Explained with Real Examples
This guide explains Linux file system paths, covering the definition of absolute and relative paths, how slashes work, practical command examples, the special '.' and '..' notations, and when to choose each approach for everyday command‑line and scripting tasks.
In Linux, a path is the reference to a file or directory, composed of names separated by slashes. The leading slash ("/") denotes the root directory, while subsequent slashes act as separators. /home/abhishek/scripts is an example of a path.
System users use paths to locate files or to tell commands and scripts where a file resides, e.g. cat /home/abhishek/scripts/my_script.sh.
Absolute Paths
An absolute path always starts from the root directory ( /). Example:
/home/abhishek/scripts/my_scripts.shRelative Paths
A relative path starts from the current working directory. If you are in /home and want to access my_script.sh, the path is:
abhishek/scripts/my_scripts.shUsing ls -l with an absolute path: ls -l /home/abhishek/scripts/my_script.sh Using ls -l with a relative path: ls -l scripts/my_script.sh Both commands produce the same file information; only the path syntax differs.
Special Relative Notations
. (single dot) – refers to the current directory.
.. (double dot) – refers to the parent directory (one level up).
To move from the abhishek directory to prakash you can use:
Absolute: cd /home/prakash Relative: cd ../prakash The .. tells cd to go up one level to /home before entering prakash.
Absolute paths are independent of the current location, while relative paths depend on it.
When to Use Which
If you are deep in a directory tree and need to move up or down a few levels, relative paths are shorter and easier to type. Conversely, when navigating across unrelated parts of the filesystem (e.g., from /home/username/project/src to /usr/bin), an absolute path avoids long chains of ../ components.
In scripts, use absolute paths when the location is fixed; use relative paths when the script may be moved or when you want it to work regardless of the installation directory.
Note: Linux filenames are case‑sensitive and may contain letters, numbers, dots, hyphens, underscores, and most characters except the slash, which is reserved as a separator.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
