I want to delete a broken link, but before that I want to confirm if the link file is present in directory. Let's call the link A
:
if [ -a A ] then
print 'ya A is ther'
fi
But if A
is a broken link then how can I check?
I want to delete a broken link, but before that I want to confirm if the link file is present in directory. Let's call the link A
:
if [ -a A ] then
print 'ya A is ther'
fi
But if A
is a broken link then how can I check?
find -L -type l
finds broken symbolic links. First confirm that the file is a symbolic link with test -L
(if it's a directory, find
would recurse into it). Thus:
is_broken_symlink () {
case $1 in -*) set "./$1";; esac
[ -L "$1" ] && [ -n "$(find -L "$1" -type l)" ]
}