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)
easier
find -L . -type l -lname ‘*’
thanks. Will try that.
Cheers
Ferg
This seems a bit more direct:
find -L . -type l
“find -L” follows sym links
so it goes out of ./ dir
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
find -L . -type l
gives me an error message:
find: invalid predicate `-L’
broken link search without pipe:
find . -type l ! -execdir test -e ‘{}’ \; -print
er, better off without the ‘ because your blog seems to turn it into the UTF-8 quotes:
find . -type l ! -execdir test -e {} \; -print
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
What’s wrong with:
find . -type l -exec rm {} \;
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!).
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)
ls -LR | grep ‘cannot access’