I was looking for a way to create hard links under Windows and I found this page: http://technet.microsoft.com/en-us/library/cc788097.aspx
To try it out, I created a file (1.txt) on the root of my C: drive with 100 lines of the following content:
C:\1.txt (2.598 bytes):
test test test test test
Then I open the command prompt and typed:
fsutil hardlink create C:\2.txt C:\1.txt
Success, 2.txt was created but when I go to see it's size it has exactly 2.598 bytes and also noticed some strange behaviours (as far as my understanding of hard links goes):
- If I delete 2.txt (the hard linked file) 1.txt is not deleted, and vice-versa.
- If I open 2.txt after I delete 1.txt (the original file) the content is still the same.
How does the fsutil hardlink create command differs from the copy command? And how can I create a true hard link under Windows?
I'm using Windows XP SP 3, and my file system is NTFS.
That's exactly the behavior that supposed to happen. Are you sure you understand how hard links work? Hard links are really just multiple entries in the file system that refer to the exact same file. If you create a hard link to a file and modify one of the instances of the file, the other file will show up with your changes because they both refer to the same blocks of data on disk.
When you delete one of the hard links, you're really just deleting one of the file system entries referring to that file. The file doesn't get deleted until you delete all of its hard links (including the original one). After you delete 1.txt, 2.txt still exists and refers to the same file that was originally there, only now there is only a single file system entry referring to that file (namely, 2.txt). 2.txt is that file.