5

Does using rm on a symlink or a hard-link remove the source in addition to the link? Is there a good way to delete a hard-link or a symlink without deleting the source?

And if there is a good way outside of rm, would it be a good idea to use this more frequently instead of rm?

1 Answer 1

7

rm always removes a link. If it's the last one, the space allocated to the file is reclaimed. However, removing a symlink doesn't affect its target, so it seems like you've been misled. If the file no longer has a name, how would you find it?

2
  • You're right, I must have done something wrong which may have mislead me. While it appeared using rm on a symlink deleted my file, I must have done something else to delete it and assumed it was rm-ing a symlink. May 30, 2019 at 22:47
  • Maybe you did a tab-completion and ended up with a forward slash at the end of the symlink and that deleted the contents of the target as noted here. stackoverflow.com/a/62647612/1745738
    – johnsnails
    Feb 22, 2023 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .