In a Unix-like operating system, an absolute pathname is a file path that specifies the location of a file or directory in the file system, starting from the root directory. Absolute pathnames always begin with a forward slash (/), which represents the root directory, and they include all the directories that lead to the file or directory in question.
For example, consider the following file hierarchy:
/ |-- home |-- user1 |-- documents |-- file1.txt
In this example, the absolute pathname of "file1.txt" would be "/home/user1/documents/file1.txt".
Absolute pathnames are useful because they provide a way to specify the exact location of a file or directory, regardless of the current working directory. This makes them especially useful in scripts and command-line utilities, where the current working directory may not be known.
Relative pathnames, on the other hand, specify the location of a file or directory relative to the current working directory. For example, the relative pathname of "file1.txt" in the above example would be "home/user1/documents/file1.txt".
To find the absolute pathname of a file or directory, you can use the realpath
or readlink -f
command in Linux, or the pwd -P
command in macOS and other Unix-like operating systems.