What is the main difference between an absolute and a relative path on Unix based systems

Those who have made use of the cd command through a terminal application on their own operating system, have probably made use of a relative path, an absolute one or both of them. Based on my personal experience with the command line, the cd command is a Unix based one and it helps the user to navigate their filesystem through the terminal application. The cd command takes the path of the file as an argument.

For example, the following command helps the user to change their current working directory to the Desktop.

What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.

cd $HOME/Desktop

You can easily find the value of $HOME by running the following command on your own terminal application. It makes use of the echo builtin shell utility.

echo $HOME

Once I managed to run the above command on my console application, the following output came out.

/Users/oltjano

Based on my personal experience with the command line on Unix based operating systems, an absolute path starts with a slash. The slash stands for the root of the entire filesystem. As you have probably guessed, an absolute path is not relative to the current working directory. On the other hand, a relative one is.

For example, the following command makes use of a relative path.

cd Test

As you can see from the above command, the relative path does not start with a slash. It is possible for it to contain forward slashes, but it does not start with one. The directory Test is a subdirectory within my Desktop.

Final thoughts

As we explained through this short blog post, the main difference between an absolute and a relative path is that the absolute one starts with a forward slash, a symbol which stands for the root directory when defined in a file path. Practically both absolute and relative paths can be handy to those who make use of the command line utilities.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Author: Rishabh

Rishabh is a full stack web and mobile developer from India. Follow me on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *