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

File Paths: Absolute vs Relative

Learn pathname resolution, differences between absolute and relative paths, and how the OS resolves them.

File Paths: Absolute vs Relative

You'll learn how operating systems interpret file paths and the key differences between absolute and relative addressing of files.

When you want to access a file, you need to tell the OS where it is. This is done through a pathname (or file path). Just like giving directions to a house, you can either specify the complete address from a known starting point, or directions relative to where you currently are.

Absolute Paths

An absolute path specifies the complete location from the root of the file system. It always starts from the same place—the root directory.

  • Unix/Linux: /home/alice/documents/report.txt
  • Windows: C:\Users\Alice\Documents\report.txt

Think of it like a full postal address: "123 Main Street, Springfield, USA." No matter where you are, this always points to the same location.

Relative Paths

A relative path specifies location starting from your current working directory. It's context-dependent.

  • documents/report.txt (go into documents subdirectory from here)
  • ../bob/notes.txt (go up one level with .., then into bob directory)
  • ./script.sh (current directory, indicated by .)

This is like saying "two blocks north, then turn left"—it only makes sense based on where you're starting.

Pathname Resolution

When the OS receives a path, it performs pathname resolution: walking through each component of the path, checking permissions, and following the directory structure until reaching the target file. Absolute paths always start from root; relative paths start from the process's current working directory (stored in the process's file descriptor table context).

Key Takeaway: Absolute paths provide fixed, context-independent file locations from the root directory, while relative paths are interpreted based on the current working directory—the OS resolves both by traversing the directory hierarchy to locate the actual file.