Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 1
    That should not be a problem. With your case, when we create hardlink to dir2 we have to make hardlink to all the contents in dir1 and so if we rename or delete dir2 only an extra link to the inode gets deleted. And that should not affect dir1 and its content as there is atleast one link (dir1) to the inode. Commented Sep 17, 2014 at 13:20
  • 5
    Your argument is incorrect. You would just unlink it, not do rm -rf. And if the link count reaches 0, then the system would know it can delete all the contents too. Commented Jun 12, 2017 at 12:55
  • 1
    That's more or less all rm does underneath anyway (unlink). See: unix.stackexchange.com/questions/151951/… This really isn't an issue, any more than it is with hardlinked files. Unlinking just removes the named reference and decrements the link count. The fact that rmdir won't delete non-empty directories is irrelevant - it wouldn't do that for dir1 either. Hardlinks aren't copies of data, they are the same actual file, hence actually "deleting" the dir2 file would erase the directory listing for dir1. You would always need to unlink. Commented Jul 11, 2019 at 0:49
  • 1
    You can't just unlink it like a normal file, because rm on a directory don't unlink it if it's non empty. See Edit. Commented Jul 12, 2019 at 7:16
  • This is just wrong. If hard links to directories were allowed, then of course the rmdir system call would not remove the inode if the link count indicated that there were other links, just as with the unlink system call. "without being incoherent with current behaviour" -- current behavior is that you can't hardlink to directories. Changing that of course implies that rmdir changes accordingly. "IMHO a sufficient reason to restrict hardlinking on directories" --- I have opinions too, but that's not what the question asks for. Commented Dec 26, 2021 at 14:02