this is a function I have in a script I use, as this does not work in FreeBSD, and I've been removing images I know I got dead links. Now I am trying to figure out how to do this in FreeBSD,
Testing round:
I created two sub-folders, put two images in one, sym linked them into another, deleted one image ran this find on it to try and delete the dead link.
it returns the broken link
Now try to delete it
what would be the proper syntex to accomplish this?
Code:
deleteDeadLinks()
{
echo "Deleting dead Links..."
#Delete any dead links to files
[[ -d "$localEterm" ]] &&
{ cd /usr/local/share/Eterm/pix/scale ;
sudo find . -xtype l -delete ;}
[[ -d "$usrEterm" ]] && { cd /usr/share/Eterm/pix/scale ;
sudo find . -xtype l -delete ; }
echo "Done deleting dead links.."
exitCode=$?
}
Code:
-links n
True if the file has n links.
-lname pattern
Like -name, but the contents of the symbolic link are matched
instead of the file name. Note that this only matches broken
symbolic links if symbolic links are being followed. This is a
GNU find extension.
Testing round:
I created two sub-folders, put two images in one, sym linked them into another, deleted one image ran this find on it to try and delete the dead link.
it returns the broken link
Code:
[userx@FreeBSD64 testscripts]$ find -L $(pwd)/link2/ -lname "*.jpg"
/home/userx/testscripts/link2/MacOS-10-14-Day.jpg
Code:
[userx@FreeBSD64 testscripts]$ find -L $(pwd)/link2/ -lname "*.jpg" -delete
find: -delete: forbidden when symlinks are followed