Find Trick: Print The Broken Symlinks

This find oneliner displays all the broken links in the current directory. By adding xargs rm, you can delete all the broken links found.

Find all the broken links:
$ find . -type l -exec sh -c "file -b {} | grep -q ^broken" \; -print

Delete all the broken links:
$ find . -type l -exec sh -c "file -b {} | grep -q ^broken" \; -print | xargs rm


Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

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


Support LinuxG via Patreon
Support on Patreon!


Subscribe to get the latest Linux news and how to guides directly on your e-mail!