Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

find(1) - peculiar behaviour

0 views
Skip to first unread message

Robin Breathe

unread,
May 30, 2002, 10:20:45 PM5/30/02
to

Hi,

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

Robin Breathe

unread,
May 30, 2002, 10:33:18 PM5/30/02
to
I wrote:
> 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.

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 ;)

void

unread,
May 30, 2002, 10:42:03 PM5/30/02
to
On Fri, May 31, 2002 at 03:33:18AM +0100, Robin Breathe wrote:
>
> 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

0 new messages