2

I was reading up on similar questions on here about what happens when you delete a hardlink to a file and the majority of the answers I was getting were that the hardlink is deleted but the original stays. However during my testing, if I have

FileA.txt and LinkFileA.txt both in separate directories, if I rm -rfv the directory that contains LinkFileA.txt, it also goes and deletes the original. Example:

home/testing/dira/FileA.txt home/testing/dirb/LinkFileA.txt

rm -rfv home/testing/dirb/* deletes both the file in dirb and the file in dira.

Why is this?

  • Could you edit your question to show the output of the rm -rfv? I'm rather surprised by the behaviour you're seeing... – Stephen Kitt May 7 '16 at 13:39
  • 4
    This command shouldn't delete both files. A hardlink or a file is a reference to the inode of the file. A file becomes inaccessible when all these references are deleted. – mazs May 7 '16 at 13:51
  • 3
    mazs is right; this also means that there is no notion of an original file when you're using hard links — all hard links are equivalent. – Stephen Kitt May 7 '16 at 14:17
  • i think there is a problem with your deletion way. just for testing , create the file and hard link in the same directory , cd into that directory and delete the hard link , and see the result. – Ijaz Ahmad Khan May 7 '16 at 14:46
1

There does seem something strange about what you're doing. This is on Debian testing x86_64:

jlquinn@cerberus:~/tmp$ mkdir dira dirb  
jlquinn@cerberus:~/tmp$ touch dira/fileA.txt  
jlquinn@cerberus:~/tmp$ ln dira/fileA.txt dirb/fileAlink.txt  
jlquinn@cerberus:~/tmp$ rm -rfv dirb/*  
removed 'dirb/fileAlink.txt'  
jlquinn@cerberus:~/tmp$ ll dira  
total 0  
-rw-r--r-- 1 jlquinn jlquinn 0 May  7 13:46 fileA.txt  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.