Links, Absolute/Relative?

Booting, installing, newbie
Post Reply
Message
Author
User avatar
DaveS
Posts: 3685
Joined: Thu 09 Oct 2008, 16:01
Location: UK

Links, Absolute/Relative?

#1 Post by DaveS »

Could somebody explain the difference between relative and absolute linking please?
Spup Frugal HD and USB
Root forever!
Bruce B

#2 Post by Bruce B »

Examples

where mount is the link

Relative

From /bin
mount -> busybox

From /usr/sbin
mount -> ../../bin/busybox

Absolute

From /bin
mount -> /bin/busybox

From /usr/sbin
mount -> /bin/busybox

Notice

If an absolute link were moved it would still point to the
true location.
User avatar
DaveS
Posts: 3685
Joined: Thu 09 Oct 2008, 16:01
Location: UK

#3 Post by DaveS »

Thanks for this Bruce. I now understand that the relative/absolute relates to the path stored in the link, not some additional property of the link. I have been experimenting with moving directories that grow such as .mozilla outside of the _save file and keeping the _save file small, with great success. I am using a complex set-up with 4.2smp with only a 256KB _save file.
BTW, Seamonkey 2 looks very promising...................
Spup Frugal HD and USB
Root forever!
User avatar
dr_willis
Posts: 47
Joined: Sat 24 May 2008, 05:33

#4 Post by dr_willis »

Also dont forget the differance between 'soft and hard links'

Those sometimes confuse people, they can also be so handy and sadly overlooked.

Biggest issue i have with relative/abs links is when im connecting to a machine via a remote box/filesystem like samba or sshfs.
Dewbie

#5 Post by Dewbie »

Just got this info from Dennis:
An absolute link is *not* a symlink. Symlink is short for "symbolic link."

*nix supports hard (absolute) links and symbolic links.

Hard links are created by

Code: Select all

ln <source> <target>
Symlinks are created by

Code: Select all

ln -s <source> <target>
The *nix file system supports indirection. A directory entry does not point to a file; it points to an inode, a kernel-maintained data structure that contains info like the file's owner, group, dates and permissions...and pointers to the blocks the file occupies on disk. So you can have more than one directory entry pointing to the same inode. This lets you have the same file appear in more than one directory, or the same file appear under more than one name in the same directory.

The vi editor is an early example of the latter usage. Vi is the full-screen \editor. Ex is a line editor. View is Vi in read-only mode, used as a viewer. All three appear in /usr/bin, and are hard links to the same executable. The program looks at which name it was called by, and assumes the appropriate personality.

*nix maintains a count of links to a file. Delete a file with multiple links, and you are deleting that link. The file itself is not removed till there is only one link to it, and you delete that.

A symlink is conceptually similar to a Windows shortcut. Instead of a hard link to a file, you have a pointer to the file. The OS follows the pointer.

The difference in terms of usage is that hard links cannot span file systems. Hard links can only be created within the same file system that the file you are linking to is on. Symbolic links *can* span file systems.

The issue that can affect symlinks is removing files. If you remove the underlying file a symlink points to, the symlink still exists, and will return a broken link error if accessed.

In general, you can use a symlink where you would use a hard link, but not vice versa because of the file system limitation on hard links.
Then I did the following:

* Shot #1:
All files are in /usr/lib. Both links were made there.

* Shot #2:
Both links moved to /usr/local; target remains in /usr/lib.

Symbolic link is now broken.
(In this case, it must be in same directory as target.)

However, absolute link is OK.
It can be moved anywhere within that file system.
And it won't break, unless the target is moved.

*Shot #3:
Now all files moved to /usr/local.

Absolute link is broken because target was moved.

Symbolic link is not broken because, although it was moved, it's in
same directory as target...just like it was in the beginning.

(And of course, if target is deleted, both links will break.)
Attachments
All-files-usr-lib.png
(10.2 KiB) Downloaded 116 times
Both-links-usr-local .png
(11.16 KiB) Downloaded 106 times
All-files-usr-local.png
(12.41 KiB) Downloaded 112 times
Post Reply