AI Hints
Home›Linux Tutorial›Moving Around
Linux · Lesson 17 of 120

Absolute and Relative Paths

Two ways to say where.

⏱ 2 min read▶ Video at 19:17🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

There are two ways to describe where a file is. Think of giving someone directions. You could give the full address, or you could say, from here, turn left. Paths work the same way.

Absolute and Relative Paths
From the video: Absolute and Relative Paths
  • Two ways to say where
  • A full address
  • Or directions from here

Two kinds of path

An absolute path starts with a slash. It begins at the root, so it works from anywhere, like a full address. A relative path doesn't start with a slash. It starts from the folder you're in right now, like directions from here.

Absolute path

  • Starts with /
  • Begins at the root
  • Works from anywhere

Relative path

  • No / at the start
  • Begins where you are
  • Shorter to type

Both reach the same file

Here we read the CV file twice, with cat, which prints a file. First with the absolute path, slash home slash sam slash Documents slash CV dot TXT. Then with the relative path, Documents slash CV dot TXT. From the home folder, both lead to exactly the same file.

Terminal
cat /home/sam/Documents/cv.txt
Sam Lee
Junior developer
Skills: Linux, Python, Git
cat Documents/cv.txt
Sam Lee
Junior developer
Skills: Linux, Python, Git

Relative paths depend on where you are

But relative paths change meaning when you move. After CD Music, the same relative path, Documents slash CV, fails, because there's no Documents folder inside Music. The absolute path would still work. That's the trade off.

Terminal
cd Music
cat Documents/cv.txt
cat: Documents/cv.txt: No such file or directory

Summary

Absolute paths start with a slash, and work from anywhere. Relative paths start from where you are. Next, a few special shortcuts in paths.

Key takeaways
  • Absolute: starts with /
  • Relative: from here
  • Relative depends on where you are
Next up: Special Paths — tilde, dot, dot dot and dash