0

Okay so I understand that this is a relatively Novice question about linux however in any case concerning hardlinks, If I create a hardlink to an existing file, then delete the original then the data is still saved under the new file correct?

So then in that case when i created the second file did it actually increase the space used up on the hard drive? say we have file1 = original file2 = hardlink to file 1.

when you instantiate file2 creating it does that increase the space used on the disk (meaning do you double the space used because you now have 2 nearly identical files, obviously i understand that they share the same inode and file2 requires a little space for it's metadata)?

then when you are deleting the file the disk space is not truly recovered until the inode is freed correct?

sorry about asking beginner questions I just need to get some things cleared up.

  • The hardlink is just another pointer to the file, so if you delete the "original" you just unlink that specific pointer. – Panki Oct 05 '21 at 22:42
  • soooo why did i receive a down-vote? – yes itsme Oct 05 '21 at 22:45
  • @yesitsme I suspect it's because of the writing; the content of the question seems all right to me. There is probably an existing duplicate question someone will identify though. – Michael Homer Oct 05 '21 at 22:51
  • @michael oh okay thanks for your feedback however that seems unfair as i did not find anything similar online to this point – yes itsme Oct 05 '21 at 23:01
  • The duplicate question isn't a problem (if it is one), I just expect that something like this has been asked before. New questions get marked as duplicates all the time and that's not a problem, it just creates a pointer to existing answers for someone looking from the same perspective as you were. I don't think that would affect the voting here, though I don't know. – Michael Homer Oct 05 '21 at 23:08
  • okay i appreciate your information – yes itsme Oct 05 '21 at 23:30
  • @MichaelHomer its just a little discouraging when its your first post here and you get downvoted as if they want to keep this stack to themselves and kick all of the new users out. – yes itsme Oct 06 '21 at 00:54
  • 1
    I've speculated on what might have led someone to a hair-trigger downvote; often people drive by a question, see something they don't like or find hard to follow, then vote and move on without thinking any further. I don't know if that was the reason or not, but I do suggest that more careful composition in your next question would be an improvement in any case and remove that possible reason. (There isn't always an explicable reason for votes in either direction). – Michael Homer Oct 06 '21 at 01:01

3 Answers3

1

Both links (names) will point at the same file (inode). They will not take up double the space.

The data (file/inode) is not freed until the last link is deleted, and until any process that might have previously opened the file has closed it.

Peregrino69
  • 2,417
1

Since the inode is the same, both file1 and file2 will refer to the same data (and therefore the same metadata), so no copy of the data is required

The referenced inode won't be freed until both file1 and file2 are deleted

One thing that may make it clearer is, if I create file1, then hard link file2 to file1, then ask you to tell me which file is the original, there's no way you could do so reliably

in short, creating a hard link simply creates a second dir_entry with identical data to the original - and the extra space taken by a hard link is the size of its dir_entry

Bravo
  • 282
0

Hardlink is just a filename alias, namely file2 and file1 pointing to the same disk inode.

Creating a hardlink indeed increase disk space but amount depends on real data. If the file only stores a byte like “a”, then filename takes more disk space. However, usually filename string is much shorter than data in file. Hence, hardlink disk space is negligible.

Zachary
  • 313