Hard links to directories: why not?

Alan J Rosenthal flaps at dgp.toronto.edu
Sat Jul 21 00:04:56 AEST 1990


boissier at irisa.fr (franck boissiere) writes:
>This problem does not seem so crucial for symbolic links.  This leads to
>the question what makes the problem crucial in one case and not in the
>other?

The fact that with symlinks, the real (hard) link is given a higher status
than the symbolic link.  So, for example, `find' can ignore symlinks and
follow hard links.  With two hard links, there's no local strategy (i.e.
a strategy whose action on small portions of the filesystem is determined
only by characteristics of that small portion) which follows only one,
except for otherwise distinguishable cases like `.' and `..'.

>Another question is when is it more appropriate to use one or the other?

Well, you have to use symlinks for directories.  Often links are used to
rearrange filesystems, like on workstations running sunos prior to v4 where
/usr is a shared filesystem but /usr/spool is private, so /usr/spool is a
symlink to /private/usr/spool; even if this were a plain file it couldn't be a
hard link because it crosses filesystems.  So, quite frequently you don't have
a choice.

When you do have a choice, I recommend symlinks for anything under maintenance,
because it's too easy to have hard links broken by moving files around.  It's
also very convenient that tar preserves symlinks.

I tentatively think it's good that things like the link from /bin/e to
/bin/ed are hard links, because it saves one block of disk space on tens of
thousands of machines, therefore saving tens of thousands of blocks.  On the
other hand, I've heard that Dennis Ritchie recommended that hard links (other
than . and ..) be removed when symlinks were added, so that there weren't two
fundamental ways to do something, and that sounds reasonable to me.

ajr



More information about the Comp.unix.wizards mailing list