rsync: how to recreate hard-links after removed and recreated a file?

Posted on

Problem :

This is what I have:

--dir1
----file1
----file2

Then I created another directory dir2 with hard-links.

--dir2
----file1 (hard link to dir1/file1)
----file2 (hard link to dir1/file2)

Now I removed file1 and recreated a new one with the same name.
How do I make the file1 in dir2 change the hard link to the new file?

Solution :

You need to rm dir2/file1 then redo the hardlink. Hardlinks are not like symlinks. Where symlinks are a pointer to an original file, hardlinks are generally indistinguishable from the original file. When you deleted dir1/file1, dir2/file1 became the new “original”. So, in order to have a hardlink named dir2/file1, you have to get this now-original-file dir2/file1 out of the way.

Leave a Reply

Your email address will not be published. Required fields are marked *