Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Oct 2012 07:14:45 +0100
From:      Matthew Seaman <>
To:        Paul Schmehl <>
Cc:        FreeBSD Questions <>
Subject:   Re: Question about find - excluding directories
Message-ID:  <>
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
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
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.
> 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



Dr Matthew J Seaman MA, D.Phil.

Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

Version: GnuPG/MacGPG2 v2.0.16 (Darwin)
Comment: Using GnuPG with Mozilla -



Want to link to this message? Use this URL: <>