From owner-freebsd-hackers Thu May 30 19:20:55 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from server1.wojo.com (server1.wojo.com [66.36.30.130]) by hub.freebsd.org (Postfix) with ESMTP id 2907037B400 for ; Thu, 30 May 2002 19:20:49 -0700 (PDT) Received: by server1.wojo.com (Postfix, from userid 502) id AFCCC3B42; Thu, 30 May 2002 22:20:47 -0400 (EDT) Received: from ishadow (pc3-oxfo3-0-cust229.oxf.cable.ntl.com [213.107.68.229]) by server1.wojo.com (Postfix) with ESMTP id BF2653B19 for ; Thu, 30 May 2002 22:20:44 -0400 (EDT) Reply-To: From: "Robin Breathe" To: Subject: find(1) - peculiar behaviour Date: Fri, 31 May 2002 03:20:45 +0100 Message-ID: <000001c20849$c6878440$026ca8c0@ishadow> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.3416 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL version=2.20 X-Spam-Level: X-Sanitizer: Anomy Sanitizer Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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