bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Suggestion: verbose option. Doc Update: -print and no action are NOT


From: James Youngman
Subject: Re: Suggestion: verbose option. Doc Update: -print and no action are NOT the same
Date: Mon, 4 Apr 2011 09:24:54 +0100

On Mon, Apr 4, 2011 at 3:35 AM, Peggy Russell
<address@hidden> wrote:
> Hi James,

Hi, I've re-added the mailing list to the CC list.  Sending questions
directly to me isn't auch a great idea; I may be slow to respond, and
other folks are not able to comment.

>>    You can omit the operator between two primaries; it defaults to
>> `-and'.  *Note Combining Primaries With Operators::, for ways to
>> connect primaries into more complex expressions.  If the expression
>> contains no actions other than `-prune', `-print' is performed on all
>> files for which the entire expression is true (*note Print File Name::).
>>
>
> I did focus on the `-prune` documentation... thinking what is it about
> `-prune` and could it apply to other find expressions.  Where the
> documentation is specific about `-prune`/true/`-print` after a test,
> the issue seems more general; More about creating compound find
> commands with multiple tests, actions, and operators.
>
> On a side note: I understand `-name` is the basename and `-path` is
> the dirname. Everything is a file. A directory can be matched
> with `-name` or `-path`, a file can only be matched with `-name` and
> `-path` if no slashes used. I almost always see `-name foo -prune`
> verses `-path ./foo -prune`. And was wondering if there was a
> technical reason? Is one more efficient than the other?

They have different meanings.    One will prune start/subdir/foo and
the other will not.

> I'm operating with the basic info:
>  - The difference between the two commands, in this doc, is "-a -print".
>  - Default starting point: '.'.
>  - Default operator: `-a`.
>  - Default action: `-a -print`.
>  - A find expression is  test [action] [operator]
>
> The data:
>  cd test
>  mkdir -p bar foo/baz
>  touch abc{1..3}.txt
>  touch foo/abc{1..3}.txt
>
> Until I read http://content.hccfl.edu/pollock/unix/findcmd.htm (see bottom of 
> page:
> "Common Gotcha") I thought examples 1 & 2 below would produce the same 
> results.
> Whether I typed  `-a -print` or not, it didn't matter, it was the default.

No, the nothing is _appended_.    If the documentation gives that
misleading impression, I need to fix it.

> There's a decision about building an expression here,
> http://stackoverflow.com/questions/637467/grouping-predicates-in-find,
> which mentions, "With a -print or other explicit action after one of the
> alternatives (but not the other), then only the alternative with the action 
> takes
> effect."  That doesn't seem like the correct answer, a little guessing, but
> it seems common.

It's true.   The -exec and -delete predicates also (from memory, I'm
not looking at the code right now) turn off the default of performing
-print when the entire expression is true.   If the documentation
doesn't make this clear, could you raise a bug report on the website
explaining where it would need to change?

> Examples 3 and 4, I also expected t see the same results. I just replaced the
> `-exec echo` with `-true`.
>
> Example (without -prune)
> ------------------------
> # 1...
> find . -name "abc2.txt" -o -name "abc1.txt" -a -print
>       ------------------------------------ ---------
>       ---------------     --------------------------
>  ./foo/abc1.txt
>  ./abc1.txt
>
> # 2...
> find . -name "abc2.txt" -o -name "abc1.txt"
>  ./foo/abc2.txt
>  ./foo/abc1.txt
>  ./abc2.txt
>  ./abc1.txt

As you mentioned, these are not the same.

> #3 "If the expression contains no actions other than `-prune', `-print' is
>   performed on all files for which the entire expression is true".

I think this needs rephrasing, would you include it in your bug report please?

>   For
>   some reason, I assumed there was an implied `-print` in the command
>   below for the  entire compound expression.
>
> find . -name "foo" -exec echo -n "hi:" \; -o -name "abc1.txt"

Of course here there is an expression with a side effect, so there is
no default -print.

>  #...Output result:
>  hi:
>
> #4 The `-exec` above has an exit status success or true. Replace `-exec` with 
> `-true`.
>    Shouldn't the output be the same as #3?

No, because -true has no side effect.

> find . -name "foo" -true -o -name "abc1.txt"
> ./foo
> ./foo/abc1.txt
> ./abc1.txt
>
> I'll have to think about this a little bit more.
>
> Thank you.
> Peggy Russell
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]