Relative vs. Absolute path
Before creating a first Bash Script, you should be well aware of the shell navigation and the difference between the relative and absolute path for an intended file. So let's understand what they are?
What is the Path?
A path to a file is a merged form of slash (/) and alpha-numeric characters. It determines the unique location of a file or directory in an OS filesystem.
An Absolute Path is a full path specifying the location of a file or directory from the root directory or start of the actual filesystem.
The relative path of a file is its location relative to the current working directory. It never starts with a slash (/). It begins with the ongoing work directory.
Relative Path Vs Absolute Path:
The topmost directory in any filesystem is the root directory denoted by the slash (/). You can describe the location of any file or directory in the filesystem with the absolute path. That means you will take every step starting from the root directory or the absolute beginning of the filesystem.
An absolute path is unambiguous and may be inconvenient to work with, especially if you are working with deeply nested directories. To get a simpler mode of the things, you can use the Relative path instead. Such that, if you are working with files in or near the present working directory, this can save you from a lot of typing.
Every time you've referred to a file by just its name, you've been using a relative path. This is the most straightforward sort of relative path. The shell looks for the specified file name within the current directory.
See these examples so that you know how the relative path is convenient over the absolute path.
1. Absolute Path
2. Relative Path
There are two commands (cd and pwd) which help in the navigation of GNU/Linux filesystem thoroughly, where,
We can easily navigate throughout the filesystem with the help of these commands using both the relative and absolute path. Just follow the given basic example.
Here, you can see how cd and pwd command help in navigation for different directories, i.e., root, parent, and home.