Linux Bash - How to delete broken symlinks in one go?

How do I get rid of all the broken symlinks I just created in a single fell swoop?

This simple one liner does the job quite fast, requires GNU find:

find . -xtype l -delete

A bit of explanation:

-xtype l tests for links that are broken (it is the opposite of -type)

-delete deletes the files directly, no need for further bothering with xargs or -exec

NOTE: -xtype l means -xtype low case L.

Mirror from

Unix/Linux StackExchange - bash- How to delete broken symlinks in one go?

Previous Post Next Post