How-to find broken symlinks
Here is easy way to find all broken symlinks:
for i in `find / -type l`; do [ -e $i ] || echo $i is broken; done
Here is easy way to find all broken symlinks:
for i in `find / -type l`; do [ -e $i ] || echo $i is broken; done
Prev Post: Automatic TCP Send and Receive Socket Buffer Sizing
Next Post: Encode movies for PDA
Main Page: ZulusTips index
You must be logged in to post a comment.
February 1st, 2007 at 10:04 am
Probably you should use –exec or pipe to xargs to improve speed and not to break for in case of many many linknames.
October 14th, 2007 at 3:44 am
find ~/ -xdev -type l -print0 | xargs -0 -I ‘{}’ sh -c “[ -e ‘{}’ ] || echo ‘{}’ is broken”
October 14th, 2007 at 6:26 am
Actually, that will fail on any file the contains a single quote in its name. So if you’re not too attached to your single quotes, you can use this:
# obliterate single-quotes from file names
find $SOME_DIRECTORY -iname “*’*” -print0 | xargs -0 rename tr/\’//d
# Function to find and remove bad links from files that don’t have single quotes in their names
find $SOME_DIRECTORY -type l -print0 | xargs -0 -I ‘{}’ sh -c “[ -e ‘{}’ ] || rm -f ‘{}’”