softlinks vs hardlinks
Hi,
I read form a source that if hardlinks to a file exist, the file can not be deleted until the hardlinks are removed? I tried this in my openSUSE 10.2 installation, and to my surprise I could remove the file with hardlinks, but the hardlinks were not behaving as links at all, rather when I created a hardlink like this: Code:
ln filename linkname |
a hard link is *NOT* a copy of a file, you clearly haven't done your reading. it is *THE* same file, but with a different name in the file table. a normal file is a file with one hard link. if you use ln to add a hard link, then it is a file with two hard links. both names are equal and one does not depend on the other.
|
But if I were to delete the original file, theoretically the other file must be deleted aswell? But that was the not the behaviour I was getting
|
you do not delete "files", you delete references (hardlinks) to spaces of disk. all the time something in the fat table references a piece of disk space, then the contents of that space is reachable as a file.
|
The number of links to the contents of your file, stored on disk, is stored.
Each time a new hard link is created, this link count is increased by one. Each time you delete a hard link, the link count is decreased by one. It's only when the link count reaches 0, that the file contents are actually marked for deletion/overwriting on the disk itself. I suggest you also read up on inodes, if this interests you. |
All times are GMT -5. The time now is 06:58 PM. |