The difference between an absolute path and a relative path lies in how they specify the location of a file or directory in the file system:
-
Absolute Path:
- An absolute path provides the complete address to a file or directory, starting from the root directory (
/). - It does not depend on the current working directory.
- Example:
/home/labex/project/file.txtis an absolute path that points directly tofile.txtfrom the root.
- An absolute path provides the complete address to a file or directory, starting from the root directory (
-
Relative Path:
- A relative path specifies the location of a file or directory in relation to the current working directory.
- It does not start from the root and can change based on where you are in the file system.
- Example: If your current directory is
/home/labex, thenproject/file.txtis a relative path tofile.txtwithin theprojectdirectory.
In summary, absolute paths are complete and fixed, while relative paths are context-dependent and shorter.
