From owner-freebsd-questions@FreeBSD.ORG Mon Oct 15 06:14:51 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id ED259A88 for ; Mon, 15 Oct 2012 06:14:50 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from smtp.infracaninophile.co.uk (smtp6.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3cd3:cd67:fafa:3d78]) by mx1.freebsd.org (Postfix) with ESMTP id 76CC68FC0A for ; Mon, 15 Oct 2012 06:14:50 +0000 (UTC) Received: from seedling.local (host86-128-112-220.range86-128.btcentralplus.com [86.128.112.220]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.5/8.14.5) with ESMTP id q9F6EjM1078818 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 15 Oct 2012 07:14:46 +0100 (BST) (envelope-from matthew@FreeBSD.org) X-DKIM: OpenDKIM Filter v2.5.2 smtp.infracaninophile.co.uk q9F6EjM1078818 Authentication-Results: smtp.infracaninophile.co.uk/q9F6EjM1078818; dkim=none (no signature); dkim-adsp=none X-Authentication-Warning: lucid-nonsense.infracaninophile.co.uk: Host host86-128-112-220.range86-128.btcentralplus.com [86.128.112.220] claimed to be seedling.local Message-ID: <507BA9D5.5020606@FreeBSD.org> Date: Mon, 15 Oct 2012 07:14:45 +0100 From: Matthew Seaman User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: Paul Schmehl Subject: Re: Question about find - excluding directories References: <7651E6A84D436D388849B985@Pauls-MacBook-Pro.local> In-Reply-To: <7651E6A84D436D388849B985@Pauls-MacBook-Pro.local> X-Enigmail-Version: 1.4.5 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig5E5AC6A02C42193B4FB9F751" X-Virus-Scanned: clamav-milter 0.97.6 at lucid-nonsense.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=2.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_PBL, RCVD_IN_RP_RNBL,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC,SPF_SOFTFAIL autolearn=no version=3.3.2 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on lucid-nonsense.infracaninophile.co.uk Cc: FreeBSD Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Oct 2012 06:14:51 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig5E5AC6A02C42193B4FB9F751 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 15/10/2012 01:32, Paul Schmehl wrote: > I want to use find to locate files that don't belong to a certain user > but should belong to that user. But there are subdirectories I want to= > exclude. >=20 > I have tried using this, but it doesn't work: >=20 > find /path/to/dir -type d ! -uid num \( -type d ! -name dirname -prune = \) >=20 > If I leave off the part in parentheses, it finds all the files I'm > looking for but also files in the subdirs I'm not interested in. >=20 > If I add the parentheses, it doesn't find any files at all. >=20 > This is FreeBSD 8.3 RELEASE. >=20 > So how can I find these files without descending into directories I'm > not interested in? Completely untested, but the usual thing with find(1) is down to the way it evaluates its arguments from left to right in a lazy fashion. So, if it has enough to know it is going to generate a true or false result after '-type d ! -uid num', it won't then go on to evaluate the rest of the line, meaning it will never see the effects of '-prune'. If you want to have exceptions, it is generally better to put them earlier in the command line: find /path/to/dir \( -type d ! -name dirname -prune \) -type d ! -uid num= Or you could use '-path' to match any path containing 'dirname' without the bracketed subexpression: find /path/to/dir -type d ! -path 'dirname*' ! -uid Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. PGP: http://www.infracaninophile.co.uk/pgpkey --------------enig5E5AC6A02C42193B4FB9F751 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.16 (Darwin) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlB7qdUACgkQ8Mjk52CukIx3VQCggA40FpMWAGdXkhjS8LyynIv2 P1sAniP6N4pUavtT+6RbFhkA24i6+Mwn =3TmU -----END PGP SIGNATURE----- --------------enig5E5AC6A02C42193B4FB9F751--