I have a case where a lot of symbolic links remain after the original file was deleted. It was the result after leaving a Jenkins installation saving all build logs until the number of available inodes got eaten up.

I would like to traverse down in the file hierarchy to find the broken links and remove them as well.

However it is important to leave some symbolic links even if they are broken. They are distinguished by their name which starts with last.

1 Answer 1


After some searching the web I came up with this:

find -L . -type l ! -name 'last*' -exec rm {} \;

The brilliant part of this command is the -L switch which tells find to follows symbolic links resulting in only the broken ones remain.

The ! -name 'last*' secures my files that should be left alone.

  • The use of find -L to delete broken links can have some unexpected consequences. See this answer.
    – John1024
    Aug 22, 2018 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.