In a Linux or UNIX file system, a relative pathname is a file or directory name that specifies the location of a file or directory in relation to the current working directory.
For example, consider the following directory structure:
refert o:lautturi.com/ |-- home | |-- user1 | | |-- documents | | |-- pictures | |-- user2 | | |-- documents | | |-- pictures |-- etc |-- var |-- tmp
If the current working directory is /home/user1
, the relative pathname documents
refers to the /home/user1/documents
directory. If the current working directory is /home/user1/pictures
, the relative pathname ../documents
refers to the /home/user1/documents
directory.
In a relative pathname, the .
symbol refers to the current working directory, and the ..
symbol refers to the parent directory of the current working directory. You can use these symbols to navigate the file system relative to the current working directory.
For example, the following relative pathnames refer to the following locations:
./documents
: The documents
directory in the current working directory../documents
: The documents
directory in the parent directory of the current working directory../../etc
: The etc
directory in the grandparent directory of the current working directoryRelative pathnames are useful because they allow you to specify file and directory locations relative to the current working directory, rather than using absolute pathnames that specify the full path to a file or directory from the root of the file system. This can be more convenient and easier to read, especially when you are working with complex directory structures.
Keep in mind that relative pathnames are interpreted relative to the current working directory, so the same relative pathname may refer to different locations depending on the current working directory. Consult the documentation and online resources for more information on working with relative pathnames in a Linux or UNIX file system.