Absolute and Relative Paths

Two ways to give directions

There are two ways to write a path:

  • An absolute path starts with /. It's the full address from the root, so it works from anywhere: /home/student/Documents/work.
  • A relative path doesn't start with /. It starts from your working directory: if you are in /home/student, then Documents/work means /home/student/Documents/work.

Think of it like this: An absolute path is like a full postal address: it works no matter where you are. A relative path is like saying "two doors down on the left": it only makes sense from where you're standing.

Both get you to the same place

cd /home/student/Documents/work
pwd
cd
cd Documents/work
pwd

In the terminal

student@vulntech:~$ cd /home/student/Documents/work
student@vulntech:~/Documents/work$ pwd
/home/student/Documents/work
student@vulntech:~/Documents/work$ cd
student@vulntech:~$ cd Documents/work
student@vulntech:~/Documents/work$ pwd
/home/student/Documents/work

The special names

NameMeansExample
/The root (at the start of a path)cd /etc
.This directoryls . is the same as ls
..The parent directorycd ../school
~Your home directoryls ~/Documents

You can mix them. From Documents/work, go up and across into school:

cd Documents/work
cd ../school
pwd

In the terminal

student@vulntech:~$ cd Documents/work
student@vulntech:~/Documents/work$ cd ../school
student@vulntech:~/Documents/school$ pwd
/home/student/Documents/school

~ makes an absolute path to something in your home, wherever you are:

cd /tmp
ls ~/Documents

In the terminal

student@vulntech:~$ cd /tmp
student@vulntech:/tmp$ ls ~/Documents
school  work

Which one should I use?

  • Relative paths are shorter when the target is close by.
  • Absolute paths are clearer and always work, which is why scripts and instructions use them.

Common mistake: cd /Documents is not your Documents folder: the leading slash means "start at the root", and there is no /Documents. Use cd Documents (relative) or cd ~/Documents.

Remember: Starts with / = absolute, from the root. Anything else = relative, from where you are. .. is up, . is here, ~ is home.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…