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.
Here is my code:
FILES=`find /target/ | grep -v '\.disabled$' | sort` for F in $FILES; do if [ -L $F ]; then DO THINGS fi done
3. Finding Broken Symlinks. The -H, -L and -P options control how symbolic links are treated, and when omitted, use -P as the default. When -P is used and find examines or prints information from a symbolic link, the details are taken from the properties of the symbolic link itself.
Use the ls -l command to check whether a given file is a symbolic link, and to find the file or directory that symbolic link point to. The first character “l”, indicates that the file is a symlink.
Using the Find Command The find command allows you to report and delete dead soft links on your system easily as well. To find broken links present in any other directory on your system, just replace the . (dot) character with the directory path.
# 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With