What is an Absolute Path and How to Write It?
An absolute path is the exact location of a file or directory in Linux. It starts from the root directory (/) and provides the complete path to the destination. It always remains the same, no matter which directory you are currently working in.
To write an absolute path, start from the root directory (/) and write the complete path of the file or directory until you reach its exact location.
Key Attributes:
- Always begins with a forward slash (/), which represents the root directory.
- Works from any current directory because it always refers to the same location.
- Points to one exact file or directory without ambiguity.
- Provides the complete path from the root directory to the destination.
Syntax:
cd /full/path/to/folder
Example 1:
In the terminal, if you are in the Documents folder and want to open the Projects folder, then type this command:
cd /home/user/Documents/Projects
Directory Structure Diagram:
/
└── home
└── user
└── Documents
└── Projects
Example 2:
Suppose you are in the Projects directory and you want to open the photo.png file, which is stored in the Desktop/Images directory. Since you are using an absolute path, you can open the file directly without changing the current directory.
Follow these steps:
Step 1: Check the current working directory.
Command:
pwd
Output:
/home/user/Documents/Projects
Step 2: Open the file using its absolute path.
Command:
xdg-open /home/user/Desktop/Images/photo.png
Result:
The photo.png file opens in the default image viewer.
Directory Structure Diagram:
Command:
tree /home/user
Output:
/
└── home
└── user
├── Documents
│ └── Projects
└── Desktop
└── Images
├── photo.png
└── otherfile.txt












