I was running a script that iterated over all the files on my Linux system and created some metadata about them, and it threw an error when it hit a broken symbolic link.
I am newish to *nix, but I get the main idea behind linking files and how broken links come to exist. As far as I know, they are like the equivalent of litter in the street. Things that a program I'm removing wasn't smart enough to tell the package manager existed, and belonged to it, or something that got left behind in an upgrade. At first, I started to tweak the script I'm running to skip them, then I thought, 'well we could always delete them while we're down here…'
I'm running Ubuntu 14.04 (Trusty Tahr). I can't see any reason not to, but before I go ahead and run this over my development system, is there any reason this might actually be a terrible idea? Do broken symlinks serve some purpose I am not aware of?
Best Answer
There are many reasons for broken symbolic links:
Resolution: remove the broken symlink.
Resolution: find the intended target and fix the link.
Resolution: find the intended target and fix the link.
Resolution: none, the link isn't broken everywhere.
Resolution: none, the link isn't broken for everybody.
Resolution: none. In this case, removing the link would be detrimental.
If you can determine that a symlink falls into the first category, then sure, go ahead and delete it. Otherwise, abstain.
A program that traverses directories recursively and cares about file contents should usually ignore broken symbolic links.