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.

[/problem]

[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.

[/solution]

[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

[/example]

[reference]

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

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

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