[CentOS] hard link a directory

Sat Jan 13 13:46:20 UTC 2007
William L. Maltby <CentOS4Bill at triad.rr.com>

On Thu, 2007-01-11 at 23:08 +0100, Andreas Rogge wrote:
> You can't.
> Ken Thompson decided that this complicates things too much so this was
> disabled back in the 70ies.
> You can however do a
> mount --bind /var/spool /home/recordings
> this has a quite similar effect.

Not quite! See below.

> 
> Regards,
> Andreas Rogge
> 
> Am Freitag, den 12.01.2007, 05:50 +0800 schrieb Mark Quitoriano:
> > Hi im trying to hard link a folder and i get this
> > 
> > # ln /var/spool /home/recordings
> > ln: `/var/spool': hard link not allowed for directory
> > 
> > how do i hard link a directory?

What you really need to do is make a new directory and hardlink all the
files from the original in the new directory.

This increments the link count for each file in the original directory
(and so also, the new directory) so that an rm of one directory's file
(s) just decrements the link count, removes the file entry in the
appropriate directory and leaves the other directory's file entry alone
(except for the reduced link count, which is not associated with the
directory anyway) and leaves the underlying file contents in place.

This is not at all like a mount --bind.

One further "gotcha": when you replace the file in one directory by "mv"
or "rm ; cp" etc., the other copy is left unaltered and it is easy to
forget that the two "copies" are no longer the same.

Before the mv/rm/cp, etc. alterations to the file from either directory
appeared in the other. This no longer occurs.

> ><snip sig stuff>

Forgive any errors, it's been decades.

HTH
--
Bill