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)

This entry was posted in Computergeekery, Tips, trivial shennanigans and tagged . Bookmark the permalink.

14 Responses to HOWTO Find broken symbolic links – Gentoo Linux Wiki

  1. Danny Rice says:

    easier

    find -L . -type l -lname ‘*’

  2. Ferg says:

    thanks. Will try that.

    Cheers
    Ferg

  3. Mark says:

    This seems a bit more direct:

    find -L . -type l

  4. UniIsland says:

    “find -L” follows sym links
    so it goes out of ./ dir

  5. Pingback: shell tip : identify broken symlinks - Tech@Sakana - A sysadmin’s blog

  6. osito says:

    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

  7. Selah says:

    find -L . -type l
    gives me an error message:
    find: invalid predicate `-L’

  8. The Mikeness says:

    broken link search without pipe:

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

  9. The Mikeness says:

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

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

  10. MagicalTux says:

    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

  11. Bill Mote says:

    What’s wrong with:

    find . -type l -exec rm {} \;

  12. Ferg says:

    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!).

  13. Bill Mote says:

    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)

  14. Shoorick says:

    ls -LR | grep ‘cannot access’

Comments are closed.