Account
Categories

Relative Paths


Definition:

A Relative Path means the location of a file or folder relative to your current directory.

When you are in the terminal, you write the path of the file or folder starting from your current location instead of the root directory.


Syntax:

cd relative-path
    

Example 1:

Current Directory: /home/user/Documents

cd Projects
    

Explanation: The command moves you into the Projects folder inside Documents.


Directory Structure:

/home
 └── user
     └── Documents
         └── Projects
    

Example 2 (Recursive):

Current Directory: /home/user/Documents

cd Projects/Code
    

Explanation: Here the path goes step by step through subfolders (ProjectsCode), making it a recursive relative path.


Directory Structure:

/home
 └── user
     └── Documents
         └── Projects
             └── Code