Account
Categories

Relative Paths


Definition:

Relative path means the path 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 from your current location.

Syntax:

cd relative-path

Example:

Suppose your current directory is:

/home/user/Documents

Command:

cd Projects

Explanation:

  • Here, Projects is a folder inside Documents.
  • You can use the relative path because it starts from your current location.
  • This helps move between folders easily without writing the full path.

Directory Structure Diagram:

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

Another Example (Recursive):

If inside Documents you have Projects/Code folder, and you are in Documents, then:

cd Projects/Code

This is also a relative path because it moves step by step through subfolders.

Directory Structure Diagram:

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