What is the difference between an absolute and a relative path?

0280

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:

  1. 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.txt is an absolute path that points directly to file.txt from the root.
  2. 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, then project/file.txt is a relative path to file.txt within the project directory.

In summary, absolute paths are complete and fixed, while relative paths are context-dependent and shorter.

0 Comments

no data
Be the first to share your comment!