I'm writing a simple crontab script to automatically find and remove
invalid symlinks.
My initial ideas relied on readlink, etc., but looking more closely at
find(1), I thought I saw a better/faster way to do it.
I think my dilemma is best illustrated by example:
[isometry@quadric:~/test]$ ls -l
total 4
lrwxr-xr-x 1 isometry isometry 8 May 31 02:01 invalidlink1 ->
fakedir1
drwxr-xr-x 2 isometry isometry 512 May 31 02:00 realdir1/
drwxr-xr-x 2 isometry isometry 512 May 31 02:00 realdir2/
lrwxr-xr-x 1 isometry isometry 8 May 31 02:00 validlink1 ->
realdir1/
lrwxr-xr-x 1 isometry isometry 8 May 31 02:00 validlink2 ->
realdir2/
[isometry@quadric:~/test]$ find -L . -type l -print
./invalidlink1
[isometry@quadric:~/test]$ find -L . -type l -delete
[isometry@quadric:~/test]$ ls -l
total 4
drwxr-xr-x 2 isometry isometry 512 May 31 02:00 realdir1/
drwxr-xr-x 2 isometry isometry 512 May 31 02:00 realdir2/
[isometry@quadric:~/test]$
The problem is that `find -L . -type l -print` reports only the "dud"
symlinks, but `find -L . -type l -delete` removes ALL symlinks... which
is clearly not the desired behaviour.
Obviously, I could just use `find -L . -type l -print | xargs rm` but
that's two more execs, which being a scrooge isn't what I want ;)
Can anyone see "what I'm doing wrong", devise a superior solution or
suggest a patch to fix this behaviour in find(1) ?
Thanks in advance,
- Robin
To Unsubscribe: send mail to majo...@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
I've just realised this is mentioned under BUGS in man 1 find, so my
query changes to: "anyone fancy fixing it and/or giving me some
pointers on how to fix it", or maybe suggest a better way for me to do
this?
"find -L . -type l -exec rm '{}' \;" strikes me as likely to be the
fastest alternative... though it's not very pretty ;)
That's likely to be more forks and execs than the xargs version,
O miserly one. :-)
--
Ben
"An art scene of delight
I created this to be ..." -- Sun Ra