Absolute path and relative path are two subject areas I see a lot of new linux/unix users struggling with learning to use the command line interface(CLI). I have to admit I struggled with it for a few days. For the most part in order to learn the difference between absolute path and relative path, you will have to just take a seat and play with the CLI until you get it. I will do my best in this blog post to explain absolute path as well as relative path for all who would like to read about it, and I will go a step further and provide a video for those who would prefer to watch a video.
Before we jump into this, just to let you know, absolute path and relative path are mainly used in html, linux/unix, and programming languages. Once you mastered the concept in one arena, it will work the exact same in another arena. In this blog post we will focus on Linux and Unix. In Linux or Unix, the absolute path is going to be the full or complete directory path to a file or a directory. To be a full directory, the path must began with the parent/root directory notated by a (/). Below are examples of an Absolute Path in Linux.
The above example is the full path to the user oracle’s desktop directory. In this example the user changed to the desktop directory by using the absolute path.
The above example is the full path to a file called network. In this example the user accessed vi editor on the network file using absolute path.
To see the absolute path or current location of where a user is in linux/unix OS, just type (pwd) for present working directory on the command line.
So you have a good understanding of absolute path, now lets take a look at relative path. Relative path is not the full or complete path, it will be the location of a file or directory that is related to the (pwd). I see the look on your face, you are like Marshae, what in the world does that means? The key word here is related. Think of it in terms of a family.
Lets say you have two brothers, a younger brother and an older brother or a brother in front of you and a brother behind you. You would be considered the (pwd). Your brothers in front of you and behind you would be considered relative directories. So let’s look at an example to help you understand:
Let’s start at the present working directory which is you, you can either go upwards or downwards. If you change directory downwards the command would look like this
This would place you in younger_brother directory.
Or you can cd up a directory and it would look like this:
Cd .. (..) means to go upwards one directory.
So as you can see, you are not using a full or complete path, you are only navigating to what is in front of you or what is behind you. You are navigating to the relative directory or relative path. Here are a few examples:
Absolute vs Relative Path
Finally, which one is preferred and which one is better to us, do I use absolute path or relative path? My answer to that question is, once you know your file system, you can determine which one is the best one to use when you need to use it. I use both of the, relative makes things a lot faster than typing the absolute path, but there are times when I need to use the absolute path when executing scripts.
The more you learn linux and are using the command line, the more comfortable you will become with using both of these paths. I can’t stress enough the best way to learn the difference between absolute vs relative path is to sit down at a Linux CLI and just do begin navigating within your Linux environment. It you focus and put your mind on this it should take no longer than an hour to master.
This was something I saw a lot of my students struggling with so I decided to create a video for my students that would make this concept easier. I hope you all enjoy the video.
At Online DBA Academy we train aspiring Oracle Database Administrators. We train students in Oracle Linux, Oracle SQL, and Oracle Database Administration. For those of you, who would like to learn more concerning the courses we offer and training to become an Oracle Database Administrator. Please reach out by emailing firstname.lastname@example.org. You can also check out our YouTube Channel: onlinedbaacademy. Visit our homepage to learn more about Online DBA Academy.
Online DBA Academy