如何检测Bash中的符号链接是否断开? [英] How can I detect whether a symlink is broken in Bash?

查看:78
本文介绍了如何检测Bash中的符号链接是否断开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I run find and iterate through the results with [ \( -L $F \) ] to collect certain symbolic links.

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

I am wondering if there is an easy way to determine if the link is broken (points to a non-existent file) in this scenario.

这是我的代码:

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中的符号链接是否断开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆