Skip to main content
2 of 9
added 302 characters in body
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
$ touch name
$ ln name othername
$ ls -l
total 0
-rw-r--r--  2 kk  wheel  0 Sep 10 09:29 name
-rw-r--r--  2 kk  wheel  0 Sep 10 09:29 othername
$ rm othername
$ ls -l
total 0
-rw-r--r--  1 kk  wheel  0 Sep 10 09:29 name

You're doing something seriously wrong if, by removing one hard link, you also remove the other. Using rm or rm -rf in this case does not matter, nor does it matter which name is removed:

$ ln name othername
$ ls -l
total 0
-rw-r--r--  2 kk  wheel  0 Sep 10 09:29 name
-rw-r--r--  2 kk  wheel  0 Sep 10 09:29 othername
$ rm -rf name
$ ls -l
total 0
-rw-r--r--  1 kk  wheel  0 Sep 10 09:29 othername

Removing a hard link just removes one of the names of the file. The only way I can see that rm -rf could remove both names is if you used it with a filename glob that matched both names, or if you deleted the directory that contained them both.

Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k