bash - 如何检测 Bash 中的符号链接(symbolic link)是否损坏?

标签 bash symlink

我运行 find 并使用 [\( -L $F\) ] 遍历结果以收集某些符号链接(symbolic link)。

我想知道在这种情况下是否有一种简单的方法来确定链接是否已损坏(指向不存在的文件)。

这是我的代码:

FILES=`find /target/ | grep -v '\.disabled$' | sort`

for F in $FILES; do
    if [ -L $F ]; then
        DO THINGS
    fi
done

最佳答案

# test if symlink is broken (by seeing if it links to an existing file)
if [ ! -e "$F" ] ; then
    # code if the symlink is broken
fi

关于bash - 如何检测 Bash 中的符号链接(symbolic link)是否损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8049132/

相关文章:

bash - 如何在 bash 中使用 grep 显示所有以 1 个大写字母开头的单词?

python - 使用 Popen 在 Python 中替换 Bash 进程

linux - 自然排序逆序?

winapi - win32api - 启用 UAC 时出现符号链接(symbolic link)创建问题?

linux - 有没有办法改变 symlink/proc/self/exe 的目标?

linux - 使用 bash 在 Linux 中获取子网掩码

android - 从 Shell 脚本安装 APK 并启动应用程序

node.js - 如何避免在 Windows 主机上的 Docker 中运行 npm 的符号链接(symbolic link)问题?

Windows:如何将驱动器符号链接(symbolic link)到另一个驱动器?

linux复制符号链接(symbolic link)