#!/bin/bash # find and optionally delete bad symlinks if [ ! -z "$1" ] ; then searchpath="$1" else searchpath="`pwd`" fi IFS=$'\n' for i in `find $searchpath -type l`; do cd "`dirname $i`" realfile="$(echo `ls -l "$i" | cut -d '>' -f 2 | cut -d ' ' -f2`)" if [ ! -e "$realfile" ] ; then echo -n "Bad symlink $i points to nonexistant file $realfile. Delete? [Y/n] " read whattodo if [ -z "$whattodo" -o "$whattodo" == "Y" -o "$whattodo" == "y" ] ; then rm -f "$i" fi fi cd - done