Skip to content
zero2vibecodelearn vibe coding
Level 1 · Files, folders, paths 6 min Reviewed by the author · Aug 4, 2026

Absolute and relative paths

A path starting with / works from anywhere. A path that does not depends on where you are standing. Knowing which is which explains most "file not found" errors.

Level 1 · 0 / 4 lessons0%

Every in the terminal is directions to a place. What differs is where the directions start from.

Absolute: from the top of the disk

An absolute path starts with /, the root of the whole disk:

/home/user/projects/site/index.html

Read it as: from the root, into home, into user, into projects, into site, and there is the file. Because it starts at a fixed point, it means the same thing no matter where you are standing.

ls /home/user/downloads

works identically from your home folder, from deep inside a project, from anywhere.

Relative: from where you are

A relative path does not start with /. It starts wherever you currently are:

ls site
cd ../archive
cat index.html

Same directions, different starting point — and the starting point is you.

Quick check

Which of these is an absolute path?

Why this is the error you will meet most

Here is the classic. A tutorial says:

cd src
npm install

You run it and get No such file or directory. The tutorial is not wrong; it just assumed you were standing in the project folder. You were somewhere else, so the relative path src pointed nowhere.

Tip

When a path-based command fails, run pwd before you do anything else. Nine times out of ten the command was fine and your location was not.

Quick check

A command that worked for a colleague fails for you with 'No such file or directory'. What do you check first?

The shorthands

Four pieces show up inside paths constantly:

PieceMeans
/the root of the disk (at the start) or a separator (in the middle)
.the folder you are in right now
..the folder one level up
~your home folder

~ is worth a second look: it is an absolute path in disguise. ~/projects expands to /home/user/projects, so it works from anywhere, just like a path starting with /. It is shorter to type and it does not hard-code your username, which is why you see it everywhere.

Note

Both forms are correct — this is not a case where one is better practice. Relative paths are shorter and survive moving a project around; absolute paths are unambiguous and survive being run from anywhere. Reach for absolute when you are unsure, relative when you are working inside one project.

Quick check

What does ~/projects expand to for the user `user`?

Try it

You start inside /home/user/projects/site.

  1. pwd — confirm where you are.
  2. ls /home/user/downloads — reach a completely different part of the disk with an absolute path, without moving.
  3. cd .. — move with a relative path, up into projects.
  4. pwd — confirm.

Notice that step 2 changed nothing about where you stand. Reading somewhere else and moving somewhere else are different actions.

Check your understanding

Answered 0/3
Mode:

How do you recognise an absolute path?

You are in `/home/user`. Which of these opens `/home/user/projects/site`?

A tutorial says `cd src` and you get "No such file or directory", even though the project has a src folder. What is the likely cause?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

Look inside downloads using its full path, then step up one level with a relative path.

Tab complete · history · Ctrl+L clear · help commands

  • Not done: List downloads by its absolute path
  • Not done: You can see what is in downloads
  • Not done: Move with a relative path
  • Not done: Finish one level up, in projects

Lesson Q&A

How do you recognise an absolute path?

The leading slash means "start from the root of the disk", so the path means the same thing from anywhere.

You are in `/home/user`. Which of these opens `/home/user/projects/site`?

From this particular folder the relative and absolute forms land in the same place. From anywhere else, only the absolute one would.

A tutorial says `cd src` and you get "No such file or directory", even though the project has a src folder. What is the likely cause?

This is the classic relative-path trap. Run pwd first, then move to where the instruction expects you to be.

Which of these is an absolute path?

Only the first starts with /. The other two are read relative to wherever you happen to be standing.

A command that worked for a colleague fails for you with 'No such file or directory'. What do you check first?

Relative paths make the same command mean different things in different folders. pwd tells you which one you are in.

What does ~/projects expand to for the user `user`?

The shell replaces ~ with the home folder path before the command runs, which makes ~/projects effectively absolute.

Move between lessons with · search with ⌘K