Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 May 2002 03:20:45 +0100
From:      "Robin Breathe" <robin@isometry.net>
To:        <hackers@freebsd.org>
Subject:   find(1) - peculiar behaviour
Message-ID:  <000001c20849$c6878440$026ca8c0@ishadow>

next in thread | raw e-mail | index | archive | help

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 majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000001c20849$c6878440$026ca8c0>