Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion find . \( -name . -o -prune \) -type f -print # does not recurse, pls explain

Received: by 10.66.81.200 with SMTP id c8mr2660213pay.1.1352354221763;
        Wed, 07 Nov 2012 21:57:01 -0800 (PST)
Message-ID: <1951354.C5Bx3R04G8@PointedEars.de>
From: Thomas 'PointedEars' Lahn <PointedE...@web.de>
Reply-To: Thomas 'PointedEars' Lahn <use...@PointedEars.de>
Organization: PointedEars Software (PES)
Date: Sat, 03 Nov 2012 19:11:12 +0100
User-Agent: KNode/4.4.11
X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject: Re: find . \( -name . -o -prune \) -type f -print # does not recurse, pls explain
Newsgroups: comp.unix.shell
References: <wroehkbsbd2.fsf@msgid.invalid.invalid> <k724cq$gqm$1@speranza.aioe.org> <1861033.xXGIKzGLs5@PointedEars.de> <wrosj8q7kw3.fsf@msgid.invalid.invalid>
Followup-To: comp.unix.shell
MIME-Version: 1.0
Lines: 79
NNTP-Posting-Date: 03 Nov 2012 19:11:13 CET
NNTP-Posting-Host: a2aafc52.newsspool2.arcor-online.net
X-Trace: DXC=gT`<=563bMOk:C4l9A;OcOA9EHlD;3YcB4Fo<]lROoRA8kF<OcfhCOKS6]dJ=QET;ADZm8W4\YJNLJ`:FmdeL>K@nLCZKh];:6AJdKJ^[bHkaO
X-Complaints-To: usenet-ab...@arcor.de
Path: s9ni86902pbb.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.mccarragher.com!news.grnet.gr!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news.musoftware.de!wum.musoftware.de!news.karotte.org!uucp.gnuu.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Bytes: 5156
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8Bit

Am Nym wrote:
^^^^^^
If that is not your real name, you better change that to it.

> Thanks to both of you for your help!  (I'm stuck w/only HP-UX find.)

You are welcome.

> Thomas 'PointedEars' Lahn <PointedE...@web.de> writes:
>> Alan Curry wrote:
>>> Am Nym  <xtdk...@gmail.com> wrote:
>>>> From web searching:
>>>>  find . \( -name . -o -prune \) -type f -print
>>>>  find . \( -name . -o -prune \) -type d -print
>> […]
>> The first `.' in the find(1) command line, indeed all positional
>> arguments before the first option is/are considered to be the directory
>> path(s) from where to start the search; in this case the current
>> directory.
> 
> I assume the \(-name . -o prune \) is considered "before the first
> option", so find further refines only it's list of dirs to decend into
> from \(-name . -o prune \); ie it's not considering filenames until
> "-type" above.

No, find(1) is a very special command (one of those that do not fully comply 
with the POSIX Utility Syntax Guidelines as specified in IEEE 1003.1, 
section 12.2).  There are options as you know them from other commands 
("options"), and there are predicates that are also options ("predicates") 
but are treated like positional arguments.

While options may be in any order (except that a warning is issued if they 
precede a positional argument or a predicate), positional arguments and 
predicates are processed in-order (to allow for short-circuit evaluation 
with -o[r], and post-processing like -exec, -printf, -print, and -ls).  
Predicates can be grouped with `( … )' to change precedence; you need to 
quote or escape find's `(' and `)' because they are part of subshell syntax 
in the shell.  Therefore, `\(-name . -o prune \)' does not work, but
`\( -name . -o prune \)' does.

So in this case, there are *no* (real) options.  There is the first 
positional argument: `.'.  The rest of the positional arguments are 
predicates.

RTFineM.
 
> --snip
>> As always, find(1) searches recursively from that directory but because
>> of `-name .' only considers the contents of the directory named so, IOW
>> that current directory.
> --snip
> 
> related example that might be useful to others:
> 
>     /tmp $ touch a b c
>     /tmp $ mkdir foo
>     /tmp $ cd foo
>     /tmp/foo $ touch e f g
>     /tmp/foo $ cd ..
>     /tmp $ mkdir bar
>     /tmp $ touch bar/{h,i,j}
>     /tmp $ find . \( -name . -o -name foo -o -prune \) -print
>     .
>     ./a
>     ./b
>     ./bar
>     ./c
>     ./foo
>     ./foo/e
>     ./foo/f
>     ./foo/g

ACK.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.