HOWTO Find broken symbolic links – Gentoo Linux Wiki

HOWTO Find broken links – Gentoo Linux Wiki

I was trying to find some broken links. however, although using
find . -type l

shows all links, it does nto use the cool flashing RED that BASH can do to shwo a broken links. So doing a quick Google turned me to this Gentoo howto: Nice n easy!
find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)

14 Replies to “HOWTO Find broken symbolic links – Gentoo Linux Wiki”

  1. To also show what the broken links used to point to:
    find -L Documents -type l -ls
    – or –
    find -L Documents -type l -exec ls -l “{}” \;
    – or –
    find -L Documents -type l -exec ls -l –color “{}” \; ## colorized

  2. broken link search without pipe:

    find . -type l ! -execdir test -e ‘{}’ \; -print

  3. er, better off without the ‘ because your blog seems to turn it into the UTF-8 quotes:

    find . -type l ! -execdir test -e {} \; -print

  4. Another one assuming you are supposed to be able to read all files.

    This will match any link to a non-readable file.

    find . -type l ! -readable

    Another one assuming you never have symlimks to symlinks:

    find . -type l -xtype l

  5. Hi Bill, your example will delete all symbolic links. Plus xargs is far neater!
    The original example is to use ‘ls -l’ so that Bash will show broken symlinks in flashing red (if setup that way!).

  6. This is what I ended up with. WAY faster than find … Thanks for everyone’s help!

    ls -d /home/me/* | (while read FN ; do test ! -d “$FN” && sudo rm $FN; done)

Comments are closed.