Date: Mon, 15 Oct 2012 07:14:45 +0100 From: Matthew Seaman <matthew@FreeBSD.org> To: Paul Schmehl <pschmehl_lists@tx.rr.com> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Question about find - excluding directories Message-ID: <507BA9D5.5020606@FreeBSD.org> In-Reply-To: <7651E6A84D436D388849B985@Pauls-MacBook-Pro.local> References: <7651E6A84D436D388849B985@Pauls-MacBook-Pro.local>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] 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. > > I have tried using this, but it doesn't work: > > find /path/to/dir -type d ! -uid num \( -type d ! -name dirname -prune \) > > 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. > > If I add the parentheses, it doesn't find any files at all. > > This is FreeBSD 8.3 RELEASE. > > 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 -- Dr Matthew J Seaman MA, D.Phil. PGP: http://www.infracaninophile.co.uk/pgpkey [-- Attachment #2 --] -----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-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?507BA9D5.5020606>
