find 命令中的“+”是做什么用的?

mtk*_*mtk 4 find

+在使用像find.

来自SO post 的示例-

find -exec touch -t 201007162310.00 \+
Run Code Online (Sandbox Code Playgroud)

请帮助我理解这个的用法。

lge*_*get 10

来自man find

-exec 命令 {} +

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 number 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.  Only one instance of `{}' is allowed within the command.  The
command is executed in the starting directory.
Run Code Online (Sandbox Code Playgroud)

例如find -exec touch -t 201007162310.00 \+,如果不带 的 find 命令-exec为您提供文件1.txt,2.txt3.txt,它将执行:

touch -t 201007162310.00 1.txt
touch -t 201007162310.00 2.txt
touch -t 201007162310.00 3.txt
Run Code Online (Sandbox Code Playgroud)

没有\+, 和

touch -t 201007162310.00 1.txt 2.txt 3.txt
Run Code Online (Sandbox Code Playgroud)

\+.

后一个版本速度更快,因为需要的新进程数量(少得多)但可移植性较差(并非所有find实现都支持它)。当然,如果您尝试使用的命令-exec不支持接收多个文件作为参数,则它将不起作用。

  • `-exec {} +` 是 POSIX 和标准的。有一次,只有 GNU find 不支持它,直到 `findutils` 4.2.12 (2005)。`-exec {} +` 是在 80 年代由 David Korn 添加到 SysV 中的。 (2认同)