Course contentsShow
← Computer Science
Lesson 1415 of 2,87232. File SystemsFree lesson

Absolute vs Relative Paths

Distinguishing between full paths from root and paths relative to current working directory.

Absolute vs Relative Paths

What you'll learn: How to distinguish between full paths that start from the root directory versus paths relative to your current working directory.

The Core Distinction

When navigating a tree-structured directory system, you need to specify where a file or directory is located. There are two ways to do this:

An absolute path (also called a full path) starts from the root directory and specifies the complete location of a file or directory. It's like giving someone your full street address: "123 Main Street, Springfield, IL 62701" — no matter where the recipient is, they can find you.

A relative path starts from your current working directory and describes how to reach the target from there. It's like saying "two blocks north, then left" — this only makes sense if you know where the speaker is standing.

Understanding Through Examples

Absolute path: /home/alice/documents/report.txt

  • Always starts with / (the root)
  • Works from anywhere in the file system
  • Complete and unambiguous

Relative path: documents/report.txt or ../bob/notes.txt

  • No leading /
  • Depends on where you currently are
  • Uses . for current directory and .. for parent directory

Think of it this way: if you're in /home/alice, the relative path documents/report.txt points to the same file as the absolute path /home/alice/documents/report.txt. But if you move to /home/bob, that same relative path would now point to /home/bob/documents/report.txt instead!

When to Use Each

Use absolute paths when you need consistency regardless of context. Use relative paths for flexibility and shorter notation when working within a known directory tree.

Key Takeaway: Absolute paths specify the complete location from root (/), while relative paths describe locations from your current working directory — both identify the same files, but in different reference frames.