find -exec 应该以 \ 结尾;或+?

iro*_*and 4 emacs find

根据man find-exec 选项必须以;.

表达式必须以分号 (``;'') 结束。

但是当我find-grep在 Emacs 中使用时,表达式以+. 我应该使用哪一种?两种表达方式有区别吗?

Dan*_*son 7

这是来自 GNU 的手册find

   -exec command ;
          Execute command; true if 0 status is returned.
          All following arguments to find are  taken  to
          be  arguments to the command until an argument
          consisting of `;'
Run Code Online (Sandbox Code Playgroud)

被我断了 但我们也有:

   -exec command {} +
          This variant of  the  -exec  action  runs  the
          specified  command  on the selected files, but
          the command line is built  by  appending  each
          selected  file name at the end; the total num?
          ber of invocations of the command will be much
          less  than  the  number of matched files.  The
          command line is built in  much  the  same  way
          that xargs builds its command lines.
Run Code Online (Sandbox Code Playgroud)

被我断了

所以,;+做不同的事情。代码中的一个简短示例来演示:

$ mkdir test
$ touch test/{a,b}
$ find test -exec echo foo {} \;
foo test
foo test/a
foo test/b
$ find test -exec echo foo {} +
foo test test/a test/b
Run Code Online (Sandbox Code Playgroud)

+只生成一个调用,其中所有匹配的文件都作为参数列表给出(实际上它的行为类似于xargs)。;为每个匹配的文件执行一次命令(;需要在 shell 中转义;因此是前面的\)。

请注意,某些版本find缺少该+选项,但 GNU 版本很可能安装在任何非嵌入式 Linux 上。