In Bash, paths are used to specify the location of files and directories. There are two types of paths: relative paths and absolute paths.
- Relative Path:
A relative path specifies the location of a file or directory relative to the current working directory. It does not start with the root directory (represented by “/”) but is based on the current location in the directory hierarchy. Common symbols used in relative paths include:
.(dot): Represents the current directory.
..(dot-dot): Represents the parent directory. For example:
./file.txt: Refers to the file
file.txtin the current directory.
../folder/file.txt: Refers to the file
folderdirectory that is one level up from the current directory. Relative paths are useful when navigating and referencing files and directories in relation to the current working directory. However, the same relative path can have different meanings depending on the current working directory.
- Absolute Path:
An absolute path specifies the complete path to a file or directory from the root directory. It starts with the root directory (“/”) and provides the full directory hierarchy to reach the target location. For example:
/home/user/file.txt: Refers to the file
userdirectory inside the
homedirectory, starting from the root directory. Absolute paths provide a fixed and unambiguous way to refer to files and directories, regardless of the current working directory. They are useful when you need to specify an exact location in the file system.
When working with paths in Bash, it’s important to understand the distinction between relative and absolute paths, as using the appropriate type ensures accurate referencing of files and directories.