Question about links (hard and sym) (Answered)

Booting, installing, newbie
Post Reply
Message
Author
diaeresis
Posts: 164
Joined: Wed 16 Sep 2009, 12:50

Question about links (hard and sym) (Answered)

#1 Post by diaeresis »

So, in the terminal I can ln or ln -s
whats the difference and how do these relate to the 'relative' and 'absolute' options I get when dragging a file/directory from one rox window to another?
diaeresis
Posts: 164
Joined: Wed 16 Sep 2009, 12:50

#2 Post by diaeresis »

OK answered it myself. Took a bit of effort as most of the stuff out there is about html design but if anyone else is interested here is a good start.

http://www.linuxformat.co.uk/forums/vie ... hp?p=79553
User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#3 Post by Pizzasgood »

A hard link points at a location on the harddrive. Every file is a hardlink. Basically, you can think of a hardlink as the name that points at the data.

Data on the harddrive "exists" as long as at least one name points at it. When there is only one name pointing at it and you delete that name, the file is considered deleted. (Actually the data is still there, but the area of the disk where it lives is now considered "free", so that when you try to write new data to the drive, it might overwrite the old "deleted" data.)

So, let's say I have a file named "bob". If I make a hardlink to bob that is named cindy, I will then have two names for the same data. They are indistinguishible. There is no way to determine which is the real one and which is the link - because they are both equally real. I can delete bob, and the data will still be there because cindy still points at it.


Symlinks (symbolic links) are different. A symlink is more like a "shortcut" from Windows (but generally better). Hard links point at data. Symlinks point at a filename. So if you have a file named "thomas" and you make a symlink to thomas named "rebecca", those are not identical. The "thomas" item points at the data. The "rebecca" item only points at thomas. If you delete thomas, rebecca will still be pointing at thomas, but since thomas isn't there, he can't point you to the data. Therefor the data is deleted, and rebecca is a broken link.


Since hard links point at actual data, they have to be on the same partition as the data they point at. Since symlinks only point at a filename, they can point at any filename on the system.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]
diaeresis
Posts: 164
Joined: Wed 16 Sep 2009, 12:50

#4 Post by diaeresis »

Ok, I think i have it but if someone could just confirm this for me.
in the terminal ln will create a hard link.
ln -s will create a symbolic link which can be either absolute or relative according to how the link name is written. A full path gives an absolute link and something else that I am not quite sure of gives a relative link. The absolute and relative links are those used by rox.
And if I want things to "just work" I should stick to absolute links when using rox.
Is that a reasonable stab at getting my head round this?

Thanks.
lapis
Posts: 184
Joined: Mon 02 Jun 2008, 08:21

#5 Post by lapis »

I had thought I understood this but after reading this thread it appears may be not. Could someone please confirm?

My understanding of absolute and relative was as follows:
Absolute: path is stored relative to /
Relative: path is stored relative to target.

Relative link and target can be moved and the link will stay intact.
If absolute link and target are moved then the link will be broken.
User avatar
Sit Heel Speak
Posts: 2595
Joined: Fri 31 Mar 2006, 03:22
Location: downwind

#6 Post by Sit Heel Speak »

(deleted by poster, erroneous. See Pizzasgood's message, below)
Last edited by Sit Heel Speak on Mon 09 Nov 2009, 01:11, edited 1 time in total.
User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#7 Post by Pizzasgood »

No no no no no.

Absolute != hard.

A hard link is a hard link. There is no concept of absolute vs. relative for hard links. They don't involve filenames at all, they point at the data on the disk.

Only a symlink can be relative or absolute. Lapis had it right:
My understanding of absolute and relative was as follows:
Absolute: path is stored relative to /
Relative: path is stored relative to target.
Also, ROX-Filer will NOT let you create a hard link. You have to do that by hand.


So, in summary:

Hard Link
  • Created with plain ln
    Points at the actual data.
    Can be moved and will point at the original data.
    Must be on the same partition as the target data.
    Is neither absolute nor relative - simply is.
    Has no arrow emblem over the icon.
Absolute Symbolic Link
  • Created with ln -s
    Points at a filename, not at the actual data in question.
    Uses an absolute path to the destination, starting from /
    Can be moved and will point at the original target if that did not move.
    Can point across partitions.
    Has an arrow emblem over the icon.
Relative Symbolic Link
  • Created with ln -s
    Points at a filename, not at the actual data in question.
    Uses a relative path to the destination, starting from wherever it is located.
    If moved, it will generally not point at the original item unless the original item was also moved so that the relative path between them stayed the same.
    Can point across partitions.
    Has an arrow emblem over the icon.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]
User avatar
Sit Heel Speak
Posts: 2595
Joined: Fri 31 Mar 2006, 03:22
Location: downwind

#8 Post by Sit Heel Speak »

I stand corrected.

From ln --help:

Code: Select all

  -s, --symbolic              make symbolic links instead of hard links
Thus I inferred, erroneously, that hard==absolute.
User avatar
DaveS
Posts: 3685
Joined: Thu 09 Oct 2008, 16:01
Location: UK

#9 Post by DaveS »

Pizzasgood wrote:No no no no no.

Absolute != hard.

A hard link is a hard link. There is no concept of absolute vs. relative for hard links. They don't involve filenames at all, they point at the data on the disk.

Only a symlink can be relative or absolute. Lapis had it right:
My understanding of absolute and relative was as follows:
Absolute: path is stored relative to /
Relative: path is stored relative to target.
Also, ROX-Filer will NOT let you create a hard link. You have to do that by hand.


So, in summary:

Hard Link
  • Created with plain ln
    Points at the actual data.
    Can be moved and will point at the original data.
    Must be on the same partition as the target data.
    Is neither absolute nor relative - simply is.
    Has no arrow emblem over the icon.
Absolute Symbolic Link
  • Created with ln -s
    Points at a filename, not at the actual data in question.
    Uses an absolute path to the destination, starting from /
    Can be moved and will point at the original target if that did not move.
    Can point across partitions.
    Has an arrow emblem over the icon.
Relative Symbolic Link
  • Created with ln -s
    Points at a filename, not at the actual data in question.
    Uses a relative path to the destination, starting from wherever it is located.
    If moved, it will generally not point at the original item unless the original item was also moved so that the relative path between them stayed the same.
    Can point across partitions.
    Has an arrow emblem over the icon.
Thanks for this Pizzasgood.............. finally, a clear concise explanation of absolute/relative linking.
Spup Frugal HD and USB
Root forever!
diaeresis
Posts: 164
Joined: Wed 16 Sep 2009, 12:50

#10 Post by diaeresis »

And thanks from here, now I have it!
Post Reply