According to the manpage of GNU find
, -print
action is used by default and
Actions which inhibit the default
-delete
,-exec
,-execdir
,-ok
,-okdir
,-fls
,-fprint
,-fprintf
,-ls
,-printf
.
So -prune
action should still imply -print
action.
Actually, it does.
$ tree .
.
├── dir/
│ └── file2
└── file1
$ find . -name dir #0
./dir
$ find . -name dir -prune #1
./dir #printed as expected
$ find . -name dir -prune -or -name file1 #2
./file1
./dir #printed as expected
However, sometimes -prune
inhibits the default -print
.
$ find . -name dir -prune -or -name file1 -print #3 #last -print is only added to the above example
./file1
$ find . -name dir -prune -or -print #4
.
./file1
How can I understand this contradiction?
My Understanding:
#1
file1
doesn't satify-name dir
so skipped.dir
satisfies-name dir
so pruned anddir
is added to TODO list.-print
is additionally applied todir
in TODO list.
#2
file1
satisfies-name file1
so added to TODO list.same as
#1
-2-print
is additionally applied todir
andfile1
in TODO list.
#3
same as
#2
-1same as
#2
-2-print
is applied tofile1
in TODO list.-print
should additionally be applied todir
because-prune
doesn't inhibit-print
. (But this is incorrect. WHY?)
#4
file1
is added to TODO list.same as
#3
-2same as
#3
-3same as
#3
-4
(Actually there is no TODO list in find
. See this comment and the standard.)
Supplement:
As pointed out in oguz ismail's answer (deleted now), my question is not related to -prune
. However, the question is not solved.
Let us think about -name A -o -name B -print
. This is broken into two expressions: -name A
or -name B -print
.
My understanding: The first expression -name A
doesn't have an action. So -print
should be implied. In other words, -name A -o -name B -print
should be interpreted as -name A -print -o -name B -print
.
Actual behavior: -name A -o -name B -print
is one compound expression. There is -print
in this compound expression. So no additional -print
should be implied.
There is ambiguity but I believe my interpretation is more natural because, in this case, only -name A
or -name B -print
is satisfied by each file (both expressions are never satisfied at the same time)