Low Orbit Flux Logo 2 F

Linux How To Remove Symbolic Or Hard Link

Removing hard links and symbolic links is really easy on Linux. You can accomplish this with the rm command. You will definitely want to check out our other guide for more details here Linux Create Hard Links and Soft Links (Symbolic).

Let’s assume for example that you have a symbolic link that looks like this:


mySymLink.txt -->  originalFile.txt

To remove the symbolic link just use the rm command like this. It will remove the link but the original file will remain.


rm mySymLink.txt

To remove a hard link you can still use the rm command with the same syntax.


rm myHardLink.txt

Removing a hard link will not remove the actual file unless every hard link to that file is removed.

If you check the second column of output from the ls command you will see the number of hard links pointing to a given file.


ls -l test1.sh

You can delete all hard links ( including the original ) with the following command:


find /home -xdev -samefile test1.txt | xargs rm