Absolute and Relative Pathnames in UNIX
Last Updated :
31 May, 2025
In Unix and Linux systems, paths define the location of files and directories within the filesystem. They are crucial for navigating and managing files efficiently. The same applies in Windows, but since most users operate through the mouse, they may not recall it as easily. In Linux, the path gives the location of a file or directory, and typically follows a specific syntax. A forward slash /
is used to separate internal and external directories.
Paths can be classified into two types: absolute paths and relative paths. Let's take a closer look at these paths.
What is an Absolute Path?
An absolute path is a full path that specifies the location of a file or directory from the root directory ('/'). It provides a complete address that points directly to a file or directory, regardless of the current working directory. This path type always begins with the root directory, followed by subdirectories, and ends with the desired file or directory name.
Example
/home/anshu/scripts/myscript.sh
- This is an absolute path because it starts from the root
/
.
Absolute PathCharacteristics of Absolute Paths:
- Starts with a slash (/).
- Specifies a file location from the root directory.
- Does not depend on the current directory.
For Example:
If you want to access a file named 'abc.sql' located in the directory '/home/kt', you would use the following command:
$cat abc.sql
This command will work only if the file "abc.sql" exists in your current directory. However, if this file is not present in your working directory and is present somewhere else say in /home/kt , then this command will work only if you will use it like shown below:
cat /home/kt/abc.sql
In the above example, if the first character of a pathname is '/', the file's location must be determined with respect to root. When you have more than one / in a pathname, for each such /, you have to descend one level in the file system like in the above 'kt' is one level below home, and thus two levels below root.
What is a Relative Path?
A relative path specifies the location of a file or directory in relation to the current working directory (often abbreviated as pwd). It does not start with a slash ('/'), and it utilizes navigational shortcuts to refer to the file or directory.
Characteristics of Relative Paths:
- Does not begin with a slash ('/').
- Dependent on the current directory.
- Utilizes shortcuts like '.' (current directory) and '..' (parent directory) to navigate the filesystem.

Using . and .. in Relative Path-names
UNIX offers a shortcut in the relative pathname- that uses either the current or parent directory as reference and specifies the path relative to it. A relative path-name uses one of these cryptic symbols:
- . (Dot): Represents the current directory.
- .. (Double Dots): Represents the parent directory.
Now, what this actually means is that if we are currently in directory '/home/kt/abc' and now you can use '..' as an argument to 'cd' to move to the parent directory /home/kt as :
$pwd
/home/kt/abc
$cd .. ***moves one level up***
$pwd
/home/kt
Note: Now '/ ' when used with '..' has a different meaning; instead of moving down a level, it moves one level up:
$pwd
/home/kt/abc ***moves two level up***
$cd ../..
$pwd
/home
Example of Absolute and Relative Path
Suppose you are currently located in 'home/kt' and you want to change your directory to 'home/kt/abc'. Let's see both the absolute and relative path concepts to do this:
1. Changing directory with relative path concept:
Use relative paths to navigate directories based on your current location in the file system.
$pwd
/home/kt
$cd abc
$pwd
/home/kt/abc
2. Changing directory with absolute path concept:
Use an absolute path to navigate directly to a specific directory from the root, regardless of your current location.
$pwd
/home/kt
$cd /home/kt/abc
$pwd
/home/kt/abc
Conclusion
Understanding absolute and relative paths is fundamental for anyone working with Unix or Linux systems. These paths not only facilitate precise file location references but also enhance efficient filesystem navigation. By mastering these concepts, users can improve their productivity and streamline their workflow in a Unix-like environment.
Similar Reads
Bash Pathname Expansion in Linux When you type a command and press enter, bash performs several processes upon the text before carrying out our command as a command. The process that makes this happen is called expansion. For example, suppose you use the echo command for standard output. echo hi Output hi If you use echo with aster
3 min read
Dirname Command in Linux with Examples dirname is a command in Linux that is used to remove the trailing forward slashes "/" from the NAME and print the remaining portion. If the argument NAME does not contain the forward slash "/" then it simply prints dot ".". In other words, we can say that the 'dirname' command is a useful tool for e
3 min read
How to Get the Full Path of a File in Linux While dealing with files on Linux, especially shell scripts, one may require determining the full path of a file at times. Now, let's consider several methods of getting the full path of a file in Linux. In this article, we will be discussing several different solutions to a popular problem.Before w
3 min read
basename Command in Linux with examples The 'basename' command in Linux is a fundamental utility used in file manipulation and script writing. It simplifies file paths by stripping directory information and optional suffixes from file names. Here a detailed overview of the 'basename' command, including its syntax, options, and practical u
3 min read
ln command in Linux with Examples The 'ln' command in Linux is a powerful utility that allows you to create links between files. These links can either be hard links or soft (symbolic) links. If you're unfamiliar with these concepts, check out our detailed guide on Hard and Soft Links in Linux to understand their differences, use ca
3 min read