Absolute and Relative Pathname
Within a UNIX file system, a file is recognized through its accurate location in the directory structure. A path name will be represents the path to be followed from root by the directory tree to locate a particular file. There are two ways through that a file can be accessed:
- Absolute path name
- Relative path name
Absolute pathname: It is the complete path name from the root in which UNIX have to be follow to reach a particular file. Absolute path name begins with a slash (/). For instance, to access the file myfile residing under the sub-directory files in the home directory, /usr/sunil, the notation is as given below
/usr/sunil/files/myfile
The initial slash (/) refers to the root directory. The given slashes separate the names of subdirectories. The last slash indicates the actual file name.
Relative Pathname: Absolute pathnames could be tedious to type if they are extremely long. Within cases a relative pathname can be used. This is the pathname in which it is shortened in relationship to the present directory position. A Relative path name is represented via a dot (.).
A particular file can be accessed relative to the present directory if the current working directory is /user/sunil. For instance, to access myfile, instead of beginning the search from the root, relative referencing begins from the present directory to get myfile as shown below.
./files/myfile
Here, dot represents the present directory. The subsequent slashes separate the subdirectories and the last slash indicates the actual file name.