How do relative paths begin?

QuestionsQuestions8 SkillsProDec, 20 2025
0130

Relative paths are defined by where you are currently "standing" (your current working directory). Unlike absolute paths, they never begin with a forward slash (/).

Instead, relative paths begin in one of three ways:

1. With a Directory or File Name

If the file or folder is located immediately inside your current directory, you simply start with its name.

  • Example: cd project
  • Meaning: "Look for a folder named 'project' right here where I am."

2. With a Single Dot (.)

The . represents the current directory. Starting a path with ./ is common when running scripts or being very explicit.

  • Example: ./script.sh
  • Meaning: "Run the file named 'script.sh' located in this exact folder."

3. With Two Dots (..)

The .. represents the parent directory (one level up).

  • Example: cd ..
  • Meaning: "Move up one level from where I am now."
  • Example: ls ../another_folder
  • Meaning: "Go up one level, then look for a folder named 'another_folder'."

Summary Comparison

Path Type Starting Character Example
Absolute Always / /home/labex/project
Relative A name, . , or .. project or ../labex

Quick Tip: If you see a path that doesn't start with /, it is a relative path! It is "relative" to the location you see when you type pwd.

0 Comments

no data
Be the first to share your comment!