Account
Categories

Absolute Path


Definition:

When you are in the terminal and want to provide the full location, you give the absolute path.

It always starts from / (root).

After / (root), you must write the full address so that it reaches the destination location.

This path can reach the destination in two ways:

  • Directly – by writing the complete address in one go.
  • Recursively – by moving step by step through folders and subfolders.

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:

When you are in the Projects directory and you want to open a file that is kept in another directory (Desktop → Images → photo.png), then follow these steps:

1. Firstly, check the present working directory:

pwd

Output:

/home/user/Documents/Projects

2. Now change the directory to the Desktop/Images folder, because this is where the file photo.png is stored.

cd /home/user/Desktop/Images

3. Check the files inside the Images folder to confirm:

ls

Output:

photo.png otherfile.txt

4. Finally, you should open the file photo.png.

xdg-open photo.png

Directory Structure Diagram:

/
└── home
   └── user
      ├── Documents
      │   └── Projects
      └── Desktop
          └── Images
              ├── photo.png
              └── otherfile.txt