Absolute Path and Relative Path (Linux OS)
There are two approaches to writing a file path – absolute path and relative path. The absolute path structure can be different by OS. The main figure illustrates the absolute path structure on Linux OS.
(For the Mac OS example, you can check Absolute Path vs. Relative Path)
Understanding these concepts is very important for setting up links to files properly. The key concepts are shown in the illustration below.
1. Absolute Path
The absolute path is a path specifying the location of a file or directory starting from the root directory. The absolute path is also called the full path. The absolute path identifies the location of a file or folder regardless of the current working directory. Thus, the absolute path is useful when the file location is fixed.
The root directory ( / )
The root directory is the topmost directory in the computer file system hierarchy. Its symbol is /
. The root directory name was initially used in Unix operating systems, but now it is also largely used in other operating systems.
Absolute URL
The absolute path is used for both local and internet environments. The path is written starting from /
(root directory) to access files on a local computer. If you want to access resources or files on the internet, the path is written starting from http:
or https:
. The absolute path written in the URL format is called the absolute URL.
2. Relative Path
The relative path is a path specifying the location of a file or directory starting from the current working directory.
Two symbols for the relative path
You need to use two symbols to describe the relative path.
- Current directory: dot (
.
) - Parent directory: double-dot (
..
)
Relative path to a descendant directory or file
Pointing to a descendant directory or file is straightforward. You just need to describe the path to the file or descendant directory as follows:
directory name a / directory name b / file name.
Relative path to an ancestor directory or file
To point to an ancestor directory or file, you need to use a double-dot (..
).
To describe a file path under the parent directory, you can write ../file name
.
To go to a further higher directory, repeat ../
.
The illustration below shows the relative path from the current directory to a file under a different branch of the directory tree.
For a better understanding of how a relative path works, check Tips: Use a relative path to access internal project resources.