Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Sep 2000 05:03:43 -0500 (CDT)
From:      Mike Meyer <mwm@mired.org>
To:        Bentley Rhodes <bentley3@mediaone.net>
Cc:        questions@freebsd.org
Subject:   Re: hard links vs soft links, plus...
Message-ID:  <14778.2815.636957.893021@guru.mired.org>
In-Reply-To: <61164815@toto.iv>

next in thread | previous in thread | raw e-mail | index | archive | help
Bentley Rhodes writes:
> i know that say. ...
>         [ ln -s /usr/whatever ]
> can be used to point to directories or files...and that
>         [ ln /usr/whatever/file(s) ]
> has to be used specifically for files (right?)....so besides that (if
> i'm right)...whats the difference in Linking?

Hard links to directories can create interesting problems. No even
remotely recent version (v6 and up, at the very least) of Unix lets
non-root users create them to directories. Some versions let root do
it via ln. Others have ln that won't let root do it, but the kernel
doesn't prevent it. Some don't ever let root do it.

> does a HARD LINK mean that i have that file on my computer?  instead of
> another users computer or area?  i guess i mean copying (cp ).....but
> that would be redundant.

Unix directories map a file name to a a file number. Basically, it's a
reference to a structure in that partition that describes the file -
who owns it, the permissions, access & update times, etc. A hard link
simply creates a second directory entry with the same file number in
it. Note that they have to be on the same partition.

> i know SOFT links redirect to the area or file...and if i [ cd .. ]
> from it , say as an FTP thing, someone could end up in my root
> directory.  so my theory is that if i make a hard link to a file...then
> basically, i still save space because the file is only like what...a
> couple of kilobytes, versus the real file?

Soft links store a path name to the "real" file. They have their own
ownership, permissions, etc (though that's usually ignored).

> bottom line...can someone fess up whats the best?

It depends on what behavior you want.

Two hard links to a file have the same status. They both refer to a
file by file number, and changes to that file will show up in
both. Changing one of the files to refer to a different file number
will mean they no longer refer to the same file. For instance, if foo
and bar both refer to the same file, and someone moves foo to foo.old
then process foo.old to create foo, bar and foo.old refer to the same
file, which is not foo.. However, if someone simply deletes foo, then
bar will still exist as a proper file.

A soft link has a different status than a hard link, because it does
the reference by name. If baz is a soft link to foo in the above, then
after the name shuffle example, baz will still refer to foo, even
though bar and foo.old are the same file. However, if someone deletes
foo, then baz will be a pionter to a nonexistent file, aka a "broken
symlink".

Bottom line: to directories and across partition boundaries, use
symlinks. You don't have any choice.

On the same file system, consider whether it's less desirable to lose
the equivalence after a move/recreate (which some editors/applications
do by default) or lose the data after a delete, and choose
accordingly.

	<mike


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?14778.2815.636957.893021>