我想知道的含义{} +
的exec
命令,之间有什么区别{} +
和{} \;
。确切地说,这两者之间有什么区别:
find . -type f -exec chmod 775 {} +
find . -type f -exec chmod 775 {} \;
Run Code Online (Sandbox Code Playgroud)
ken*_*orb 40
必须使用;
(分号) 或+
(加号) 来终止-exec
/调用的 shell 命令execdir
。
;
(分号)或+
(加号)之间的区别在于如何将参数传递到 find 的-exec
/-execdir
参数中。例如:
using;
将执行多个命令(对每个参数分别执行),
例子:
$ find /etc/rc* -exec echo Arg: {} ';'
Arg: /etc/rc.common
Arg: /etc/rc.common~previous
Arg: /etc/rc.local
Arg: /etc/rc.netboot
Run Code Online (Sandbox Code Playgroud)
以下所有参数
find
都被视为命令的参数。该字符串
{}
由当前正在处理的文件名替换。
using+
将执行尽可能少的命令(因为参数组合在一起)。它与xargs
命令的工作方式非常相似,因此它将为每个命令使用尽可能多的参数,以避免超过每行参数的最大限制。
例子:
$ find /etc/rc* -exec echo Arg: {} '+'
Arg: /etc/rc.common /etc/rc.common~previous /etc/rc.local /etc/rc.netboot
Run Code Online (Sandbox Code Playgroud)
命令行是通过在末尾附加每个选定的文件名来构建的。
命令中只
{}
允许一个实例。
也可以看看:
小智 32
鉴于命令 find 获得以下三个文件:
fileA
fileB
fileC
Run Code Online (Sandbox Code Playgroud)
如果使用-exec
加号( +
),
find . -type f -exec chmod 775 {} +
Run Code Online (Sandbox Code Playgroud)
这将是:
chmod 775 fileA fileB fileC
Run Code Online (Sandbox Code Playgroud)
命令行是通过在末尾附加每个匹配的文件名来xargs
构建的,这与构建其命令行的方式相同。命令的调用总数(chmod
在本例中为 )将远小于匹配文件的数量。
如果使用-exec
分号( ;
),
find . -type f -exec chmod 775 {} \;
Run Code Online (Sandbox Code Playgroud)
这将是:
chmod 775 fileA
chmod 775 fileB
chmod 775 fileC
Run Code Online (Sandbox Code Playgroud)
小智 5
根据man find
:
-exec command {} +这个 -exec 动作的变体在选定的文件上运行指定的命令,但是命令行是通过在每个选定的文件名后附加来构建的;命令的总调用次数将远小于匹配文件的数量。命令行的构建方式与 xargs 构建其命令行的方式非常相似。命令中只允许有一个“{}”实例。该命令在起始目录中执行。