A path can be written from the root of the system or from the current directory. Its first character tells you which of the two you are looking at.
All files and directories in Linux form a single tree. It starts at the root, the directory /. The root holds home, etc, and other directories, home holds the users' home directories, and so on down. A path lists the directories on the way to a file, separated by /.
An absolute path starts with / and is counted from the root. /home/student/path-lab/project/config/site.conf leads to the same file whatever directory you are in.
A relative path starts with a name and is counted from the current directory. From ~/path-lab/project, config/site.conf leads to your colleague's file. From ~/path-lab it leads into ~/path-lab/config, and there is no such directory.
| Path | Counted from |
|---|---|
absolute, /home/student/path-lab |
the root / |
relative, project/config |
the current directory |
At the start of a path, the shell replaces ~ with your home directory: ~/path-lab is the same as /home/student/path-lab.
The instructions say to open etc/nginx/nginx.conf. You are in /home/student. What happens?
-
cd ~takes you to/home/student, where you already are. The path would work from the root, aftercd /. -
The shell follows the path from the current directory. Searching by name is what
finddoes, covered in the search step. -
Without a leading
/the path is counted from the current directory, so the file is looked for in/home/student/etc/nginx./etc/nginx/nginx.confis the path from the root.
etc/nginx/nginx.conf is a relative path: it starts with a name and is counted from /home/student, which has no etc directory. You need the absolute /etc/nginx/nginx.conf, which works from any directory.
Key points
-
An absolute path starts with
/and leads to the same place from any directory. - A relative path is counted from the current directory and changes meaning along with it.