Skip site navigation (1)Skip section navigation (2)
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
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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?507BA9D5.5020606>