一个删除无效链接的脚本

来源:互联网 发布:21天学通c语言高清pdf 编辑:程序博客网 时间:2024/05/17 23:59
一个删除无效链接的脚本   #!/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
 
原创粉丝点击