How do you use absolute vs relative paths with an example?

In Linux, there are two ways to specify the location of files and directories: absolute paths and relative paths. Understanding these two types of paths is essential for navigating the file system effectively.

absolute path, relative path, Linux navigation, file system, command line

This guide explains the difference between absolute and relative paths in Linux, including practical examples to help you understand how to navigate your file system effectively.

Absolute Path: An absolute path specifies the complete location of a file or directory from the root directory. It starts with a forward slash (/). For example, the absolute path to a file named 'example.txt' in a directory structure could be:

/home/user/documents/example.txt

Relative Path: A relative path specifies the location of a file or directory relative to the current working directory. It does not start with a forward slash. For example, if your current directory is '/home/user', the relative path to 'example.txt' in the 'documents' directory would be:

documents/example.txt

Using these paths correctly will greatly enhance your efficiency when working with the Linux command line.


absolute path relative path Linux navigation file system command line