由于未安装 bash,因此我必须在 korn 中执行此操作。这是我目前的脚本,但它并没有像我预期的那样工作。
cd /
find . -xdev -type d > /tmp/dirlist
export YOURLIST=`cat /tmp/dirlist2`
echo START > /tmp/final
for a in $YOURLIST; do
export MYLIST=`ll $a | grep "\->" | awk '{print $11;}'`
echo in dir $a >> /tmp/final
sleep 5
for b in $MYLIST; do
echo `ll $b` 2>&1 > /tmp/result
grep -q not /tmp/result
export RC=$?
if [ "$RC" = "0" ]
then
cat /tmp/result >> /tmp/final
fi
done
done
目前它只打印目录,/tmp/final
并且仍然显示未找到奇怪的是,信息stdout
。
答案1
find
应该能够找到符号链接,你不必依赖解析ls
。
find / -xdev -type l -print |
while IFS= read -r f; do
target=$(readlink "$f")
[[ -e "$target" ]] || echo "broken symlink: $f -> $target"
done
答案2
做了两件事来模拟 Glenn 的回应中缺失的内容
root@system:/ $ cat /bin/checklink
export ORIGINAL=`ll $1 | awk '{print $9;}'`
export ORIGINALDIR=`dirname $ORIGINAL`
export LINKIS=`ll $1 | awk '{print $11;}'`
export FOUND="0"
if [ -d ${ORIGINALDIR}/${LINKIS} ]
then
export FOUND="1"
else if [ -f ${ORIGINALDIR}/${LINKIS} ]
then
export FOUND="2"
else if [ -d ${LINKIS} ]
then
export FOUND="3"
else if [ -f ${LINKIS} ]
then
export FOUND="4"
fi
fi
fi
fi
if [ "$FOUND" = "0" ]
then
echo $1 pointing to $LINKIS not found
fi
随后致电
`find / -xdev -type l -exec checklink {} \;
请随意改进...