Code: Select all
#!/bin/sh
## finds broken links in pwd
#. colors adds colors if file exists
[ -f /tmp/links ] && rm /tmp/links
[ -f /tmp/target ] && rm /tmp/target
dir=`pwd`
[ -f /tmp/log ] && rm /tmp/log
LOG="/tmp/log"
ls -l | grep ">" >>/tmp/links
echo
echo -e ${RED}"Broken Links in `pwd`"${WHITE}
echo "_____________________"
echo
while read line; do
link=`echo "$line" | awk '{print $8}'`
target=`echo "$line" | cut -d\> -f2`
var=`ls ${target} 2>>$LOG`
[ "$var" ] || echo $link
done</tmp/links
echo
sed -e 's/ls: cannot access//g' /tmp/log