![]() |
VOOZH | about |
When files are organized as a directory tree, there must be a way to uniquely identify and access them. This is done through path names. A path name specifies the location of a file or directory in the file system hierarchy. There are two main types of path names:
An absolute path name (also known as a full path) specifies the complete path from the root directory ("/") to the target file or directory. It does not depend on the current working directory, which makes it unique and unambiguous.
UNIX/Linux:
/var/mail/usernameWindows:
C:\Users\Username\AppData\Local\Microsoft\Outlook\
Here,
/ (or C:\) represents the root directory.Absolute path names are used when:
cp /usr/ast/mailbox /usr/ast/mailbox.bak
This command copies the file mailbox from /usr/ast/ to a backup file in the same directory, using absolute paths.
A relative path name specifies the file or directory in relation to the current working directory (also known as the present working directory). It does not start from the root and is shorter and more flexible than an absolute path.
If the current working directory is:
/usr/ast
Then the absolute path /usr/ast/mailbox can be referred to simply as:
mailbox
cp mailbox mailbox.bak
This command performs the same operation as the earlier absolute path example, assuming the working directory is /usr/ast.
Relative path names are used when:
The working directory (or current directory) is the directory that the operating system considers as the default for all relative path operations.
You can: View it using:
pwd
Change it using:
cd /usr/ast
Once the working directory is set, all file operations using relative paths are performed relative to this directory.
| Criteria | Absolute Path | Relative Path |
|---|---|---|
| Definition | Full path from root directory | Path relative to current working directory |
| Dependency | Independent of working directory | Depends on working directory |
| Uniqueness | Always unique | May vary depending on current directory |
| Usage | Used in scripts or programs requiring fixed file references | Used in user-level commands or local navigation |
| Example (UNIX) | /usr/lib/dictionary | ../lib/dictionary |
Absolute paths are preferred when:
Example: A spell-checking program may need to read the dictionary file at:
/usr/lib/dictionary
Since the working directory during execution may vary, using an absolute path ensures it always finds the file correctly.