Absloute path vs relative path in Linux/Unix

One of this blog follower asked us that what’s the difference between absolute and relative path?

To understand this we have to know what is a path in Linux.

What is a path?

A path is a unique location to a file or a folder in a file system of an OS. A path to a file is a combination of / and alpha-numeric characters. Share Image

What is an absolute path?

An absolute path is defined as the specifying the location of a file or directory from the root directory(/). In other words we can say absolute path is a complete path from start of actual filesystem from / directory.

Some examples of absolute path:


If you see all these paths started from / directory which is a root directory for every Linux/Unix machines.

What is the relative path?

Relative path is defined as path related to the present working directory(pwd). Suppose I am located in /var/log and I want to change directory to /var/log/kernel. I can use relative path concept to change directory to kernel

changing directory to /var/log/kernel by using relative path concept.

cd kernel

Note: If you observe there is no / before kernel which indicates it’s a relative directory to present working directory.

Changing directory to /var/log/kernel using absolute path concept.

cd /var/log/kernel

Note: We can use an absolute path from any location where as if you want to use relative path we should be present in a directory where we are going to specify relative to that present working directory.

Examples of relative path and absolute path for the same operation.

Example1: Present location is /abc/xyz, I am want to remove /abc/xyz/read/hello.txt file.

Using relative path:

rm read/hello.txt

Using absolute path:

rm /abc/xyz/read/hello.txt

Example2: My present location is /etc/samba and now I want to change directory to /etc.

Using relative path:

cd ..

Using absolute path:

cd /etc

Example3: My present location is /var/ftp/ and I want to change the location to /var/log

Using relative path:

cd ../log

Using absolute path:

cd /var/log

Example4: My present location is /etc/lvm and I want to change my location to /opt/oradba

Using relative path:

cd ../../opt/oradba

Using absolute path:

cd /opt/oradba

Example5: My present location is /usr/local and I want to remove a abc.txt file located in this directory how can I do that?

Using relative path:

rm abc.txt

Using absolute path:

rm /usr/local/abc.txt

I hope this helps to understand the difference between Absolute and relative path.

Show your love by sharing this..!
Share on VKShare on StumbleUponShare on YummlyPrint this pageFlattr the authorShare on TumblrEmail this to someoneBuffer this pageShare on Google+Share on LinkedInShare on FacebookTweet about this on TwitterPin on PinterestShare on RedditDigg this
The following two tabs change content below.
My name is Surendra Kumar Anne. I hail from Vijayawada which is capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. I work with ICE systems, Sydney as Sr. Consultant. You can contact me at surendra (@) linuxnix dot com.

  • Pingback: 23 Linux cd command examples()

  • http://www.facebook.com/preet.royal.chandigarh Royal Preet Chandigarh

    Nice explanation …. :)

  • Pingback: Compilando mediante la variable CLASSPATH en el bash de Linux | danielmbcn()

  • Badal

    it’s very nicely written 😛

  • http://www.facebook.com/zothans Sanga Zothan

    Really Good example. the most simple and easy to understand e.g i could find in the internet world.

  • http://none Shey

    nice example sir.

    • http://www.linuxnix.com Surendra Anne

      Thanks for complements Shey

  • james

    this was very helpful. Thank you!

  • Shane

    Makes so much more sense now. Thanks!

  • sarath

    perfect. basic linux commands 

  • Omkar

    This is very helpful and great explanation.