Removing links to missing files

Problem

You have many symbolic links that point to missing files.

I guess it is all just about good housekeeping! 🙂 Well and the fact your application might break, depending on something being there, that is not.



Solution

This bit of shell under example tab, deals with them swiftly and sharply. 🙂

Effectively it just does a find from the current directory, then loops around looking for missing files.



Example



for na in `find . -type l`
do
ls -lLd $na 2>&1 | grep "No such file" |
while read junk delme junk
do
rm ${delme%:}
done
done



Reference

[tags]symbolic links, find, rm, while, UNIX Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *