Operating System - Linux
1819681 Members
3665 Online
109605 Solutions
New Discussion юеВ

Absolute path & Relative Path

 
Indrajit Bhagat
Regular Advisor

Absolute path & Relative Path

Dear Sir,
I want to know what is the difference between Relative Path and Absolute Path.
5 REPLIES 5
Torsten.
Acclaimed Contributor

Re: Absolute path & Relative Path

Hi,

the absolute path begins always with "/" - the relative path is (like the name suggests) relative - in every respect, depending on your current working directory.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Patrick Wallek
Honored Contributor

Re: Absolute path & Relative Path

Showing an example would probably be easiest.

Let's say that you are in a directory called /abc/def and in that directory are other directories ghi and jkl.

Now if you wanted to back up ghi and jkl with tar using Absolute path you would do:

# cd /abc/def
# tar -cvf ghi_jkl.tar /abc/def/ghi /abc/def/jkl

Absolute path means specifying the ENTIRE path to the directory you want to back up. When you restore this it will be restored to the SAME EXACT path (/abc/def/ghi).

Now, if you want to back up ghi and jkl with relative paths, you would do:

# cd /abc/def
# tar -cvf ghi_jkl2.tar ghi jkl
or
# tar -cvf ghi_jkl3.tar ./ghi ./jkl

Both of the above commands accomplish the same thing. The 2nd command (with ghi_jkl3.tar) will just have a ./ in front of the directory names. The first will not.

Relative path means the directory names are relative to your current directory.

If you wanted to restore from one of these tar file to a diffferent directory it is easy because you used relative.

If you want to restore ghi and jkl into /abc/mno, then you would do:

# mkdir /abc/mno
# cd /abc/mno
# tar -xvf ghi_jkl2.tar
or
# tar -xvf ghi_jkl3.tar

Now you will have /abc/mno/ghi and /abc/mno/jkl.

I much prefer dealing with relative pathing with commands like tar. It makes restores to different directories a whole lot easier.

I hope this explains it well enough for you.
inventsekar_1
Respected Contributor

Re: Absolute path & Relative Path

Absolute path: the name itself says that its is "absolute". it starts with "/" (root)

Relative path means relative to the current position or directory.

some commands requires absolute path. best example is "swinstall"

Be Tomorrow, Today.
KapilRaj
Honored Contributor

Re: Absolute path & Relative Path

Location w.r.t the root of the directory tree is absolute path. And location w.r.t the current location is relative path.
Nothing is impossible
A. Clay Stephenson
Acclaimed Contributor

Re: Absolute path & Relative Path

Everything that has been said so far is true; however, there is a wrinkle that should not be overlooked and that is chroot -- which is both a system call and a command. Chroot has the ability to change the root of the file tree so that, for example, eventhough the pathname of a program might be /bin/myprogram, chroot might have set the top of the tree to something like "/mickey/mouse" so that when you execute "/bin/myprogram" which has an absolute path, you are actually executing "/mickey/mouse/bin/myprogram".
If it ain't broke, I can fix that.