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, thenDocuments/workmeans/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
pwdIn 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
| Name | Means | Example |
|---|---|---|
/ | The root (at the start of a path) | cd /etc |
. | This directory | ls . is the same as ls |
.. | The parent directory | cd ../school |
~ | Your home directory | ls ~/Documents |
You can mix them. From Documents/work, go up and across into school:
cd Documents/work
cd ../school
pwdIn 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 ~/DocumentsIn 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 /Documentsis not your Documents folder: the leading slash means "start at the root", and there is no/Documents. Usecd Documents(relative) orcd ~/Documents.
Remember: Starts with
/= absolute, from the root. Anything else = relative, from where you are...is up,.is here,~is home.