linux删除无效链接文件脚本分享
linux终端下执行,用于删除无效的链接文件。
#!/bin/sh
usage()
{
echo "removebroken 0.1, a shell script to remove broken link files."
echo "license: mit, (c) chenzhiqiang"
echo "usage:"
echo " $0 --help print this help."
echo " $0 --path path broken links under this path will be removed."
echo " $0 --stdin read paths from stdin."
echo " $0 same as $0 --stdin."
}
fromstdin()
{
while [ 1==1 ]
do
read
[ "$reply" != "" ] || exit 0
[ ! -l $reply -o -e $reply ] || unlink $reply
done
}
frompath()
{
find $2 | $0 --stdin
}
if [ $# = 0 ]
then
usage
fromstdin
exit 0
fi
case $1 in
--stdin)
fromstdin
--path)
find $2 | $0 --stdin
--help)
usage
*)
echo "removebroken: unknown usage."
usage
esac
下一篇: SHELL四则运算和比较