脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - shell - linux删除无效链接文件脚本分享

linux删除无效链接文件脚本分享

2022-12-28 15:27脚本之家 shell

一个 shell 脚本文件,用于删除指定目录下无效链接文件,可利用标准输入指派多个处理目标

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

 

延伸 · 阅读

精彩推荐