Home Linux Linux : Absolute Paths and Relative Paths

Linux : Absolute Paths and Relative Paths

by Anup Maurya
12 minutes read

In Linux, a path is a string of characters that specifies the location of a file or directory in the file system. Paths are used to navigate through the file system and access files and directories.

There are two types of paths in Linux: absolute paths and relative paths.

Absolute Paths

An absolute path specifies the location of a file or directory from the root directory. The root directory is denoted by a forward slash (/).

For example, the absolute path to the /etc directory is:

/etc

This means that the etc directory is located directly in the root directory.

Absolute paths always start with a forward slash (/), and every directory in the path is separated by a forward slash (/). For example:

/home/user/Documents/myfile.txt

This absolute path specifies that the file “myfile.txt” is located in the “Documents” directory, which is located in the “user” directory, which is located in the “home” directory, which is located in the root directory.

Relative Paths

A relative path specifies the location of a file or directory relative to the current directory. The current directory is the directory that you are currently in.

Relative paths do not start with a forward slash (/). Instead, they start with the name of a directory or file. For example:

../

This relative path specifies the parent directory of the current directory. The double dots (..) are used to indicate the parent directory.

./

This relative path specifies the current directory. The single dot (.) is used to indicate the current directory.

Documents/myfile.txt

This relative path specifies that the file “myfile.txt” is located in the “Documents” directory, which is located in the current directory.

Relative paths are useful for navigating through the file system without having to specify the entire path from the root directory.

Conclusion

Paths are an essential part of navigating through the Linux file system. Absolute paths specify the location of a file or directory from the root directory, while relative paths specify the location of a file or directory relative to the current directory. Understanding and using paths effectively is crucial for working with files and directories in Linux.

related posts

Leave a Comment