about an example in Linux find man page

about an example in Linux find man page

The following example in Linux find man page doesn't seem to work:

   find repo/ -exec test -d {}/.svn \; -or \
   -exec test -d {}/.git \; -or -exec test -d {}/CVS \; \
   -print -prune

   Given the following directory of projects and their associated SCM
   administrative directories, perform an efficient search for the
   projects' roots:

   repo/project1/CVS
   repo/gnu/project2/.svn
   repo/gnu/project3/.svn
   repo/gnu/project3/src/.svn
   repo/project4/.git

   In this example, -prune prevents unnecessary descent into directories
   that have already been discovered (for example we do not search
   project3/src because we already found project3/.svn), but ensures
   sibling directories (project2 and project3) are found.

The find displays no output. Does anybody know why? I noticed this find had no tests since "-exec" clause are actions not tests (can an action be a test too?). and since "-or" has lower precedence than implied "-and" between the last "-exec" and "-print", the logic expressed in the command line doesn't seem to be what it was intended to be.

>uname -r
 2.6.32-131.0.15.el6.x86_64
>pwd
 /var/tmp
>mkdir -p repo/project1
>mkdir -p repo/gnu/project2
>mkdir -p repo/gnu/project3/src
>mkdir -p repo/project4
>touch repo/project1/CVS
>touch repo/gnu/project2/.svn
>touch repo/gnu/project3/.svn
>touch repo/gnu/project3/src/.svn
>touch repo/project4/.git

>find repo
repo
repo/project4
repo/project4/.git
repo/gnu
repo/gnu/project3
repo/gnu/project3/src
repo/gnu/project3/src/.svn
repo/gnu/project3/.svn
repo/gnu/project2
repo/gnu/project2/.svn
repo/project1
repo/project1/CVS

>find repo/ -exec test -d {}/.svn \; -or -exec test -d {}/.git \; -or -exec test -d {}/CVS \; -print -prune
>

答案1

The example is bad. It's doing

find -exec command1 \; -or -exec command2 \; -or -exec command3 \; -print -prune

Which is equivilent to

find -exec command1 \; -or -exec command2 \; -or -exec command3 \; -and -print -and -prune

But since -and (-a) has higher presedence than -or (-o), the -print and -prune are only applied to -command3

Bug Report

About test. You're confusing tests in the find man page, which is simply what they call a specific groups of their operators, with the test command that's used above.

答案2

What man find writes about exec in the first sentence should answer your question:

   -exec command ;
          Execute command; **true if 0 status** is returned.

相关内容