Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15177114
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-05-03 10:53:19

感谢作者: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<>
#
                                                                                 
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
阅读(1425) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~