博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

剑心通明的资料库

文章均为转载,本人不负因参考它所导致的一切后果,请谨慎参考!如您的文章不愿被转载,请点击此处联系本人!
  jxtm.cublog.cn

关于作者
姓名:剑心通明
职业:高级工程师(专修灵魂^_^)
年龄:20出头30不到
位置:网络上一节点
个性介绍:努力学习每一天!
倾心打造:http://www.bsdlover.cn
http://bbs.bsdlover.cn
BSD爱好者的乐园!
|| << >> ||
我的分类


一个删除无效链接的shell脚本
感谢作者:home_king兄
说明
1.专家模式(删除前免提示),且进入专家模式前作出提示
2.仅作用于一层目录的功能选项
3.该脚本利用find的目录递归功能删除系统上无效(目标文件不存在)的软链接

代码:

#!/bin/sh
# When lpath is /, it can delete all null links existing in your system INTERACTIVELY!!!
#
# Written by home_king<home_king@163.com>
#
                                                                                 
prompthelp()
{
        echo ========================================
        echo 'Delete symbolic links with null target.'
        echo 'usage:dellink [-e] [-o] [PATH]'
        echo '  -f:EXPERT mode,no prompt.WARNNING!!!'
        echo '  -c:Just apply to current directory.'
        echo '  -h:Print this help.'
        echo '  Without PATH, we set it ".".'
        echo ========================================
}
delflag=""
promptdel()
{
        read -p 'WARNNING!!!Without PROMPT!!!Continue?[y/n]' delflag
        case $delflag in
                y ) return 0;;
                n ) exit 1;;
                * ) promptdel
        esac
}
while getopts ":fch" opt; do
        case $opt in
                f  ) INTERACTIVE="f"
                     promptdel;;
                c  ) DEPTH="maxdepth 1";;
                h  ) prompthelp
                     exit 0;;
                ? ) echo "Invalid Option!"
                     prompthelp
                     exit 1
        esac
done
shift $(($OPTIND - 1))
lpath=$1
[ $# -gt 1 ] && prompthelp && exit 1
if [ -d $1 ]; then
        linklist=$(find $1 -${DEPTH:-"depth"} -type l |xargs)
        for i in $linklist; do
                [ ! -f $i ] && rm -${INTERACTIVE:-"i"} $i
        done
else
        echo "PATH is not a directory!"
        prompthelp
fi

 原文地址 http://www.bsdlover.cn/html/22/n-822.html
发表于: 2008-05-03,修改于: 2008-05-03 10:53,已浏览377次,有评论0条 推荐 投诉


网友评论
 发表评论