Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
softlinks vs hardlinks
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:
ln filename linkname
Then removed filename, the file named linkname was an exact copy of the original file, and rm gave no errors removing the original file. Rather symbolic links behaved as links, and if the original file was removed the link became invalid, rather the hardlink retained the content? So what is the difference b/w simple copy and a hardlink then?
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.
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.