[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to hard link directories?



On Tue, 2010-03-16 at 23:09 -0500, Jason M. Schindler wrote:
> > I'd like to create a hard link between
> >
> >         /pub/fedora/linux/development/13/
> >          and
> >         /pub/fedora/linux/updates/13/
> >
> > such that the contents of ./updates/13 exactly match those
> > of ./development/13 without consuming any more disk space.
> >
> > I've been hammering away at various combinations and permutations of
> > 'ln' without any luck. Is ln the correct utility to use? If so, what's
> > the syntax I should use?
> >
> > --Doc
> 
> Doc,
> 
> I don't think you can hard link directories.  Why not use a soft link?
> 
> -Jason

Jason,

If you look carefully, you'll find some real relics (fossils?) scattered
throughout most Linux and UNIX distributions. The man page for the ln
link utility is one of these. Except for recent insertions of copyright
statements, I don't think it has been changed since it was originally
written the '70s. Except for a veiled warning in the -d option, there's
nothing that explicitly says you can't hard link directories. Would that
be so inappropriate or hard to do?

You ask "Why not use a soft link?" I'm glad you asked me that question.
Aside from its obvious visual messiness in a directory display, a soft
link is different from a hard link in subtle ways that I'd rather not
have to deal with in scripts. For example, if I have two hard links to a
file they're each a separate directory entry pointing to a set of inodes
containing the data. If I delete one, the other remains intact. If
instead I have a file and a soft link to that same file, the soft link
points not to the inodes containing the data but to the original
directory entry. If I delete the actual file a broken soft link is
created.

The mount method that Nathan has suggested has merits that lie somewhere
between these two alternatives. It doesn't offer the file deletion
protection afforded by hard links -- when I delete a file in either
tree, it's removed from both. ("You want that cheeseburger to go? ...
It's GONE!") On the other hand, there's no leftover broken soft link to
clean up.

--Doc


-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.