我想知道到底是什么{} \;和{} \+和| xargs ...做的。请通过解释加以澄清。
下面的3条命令运行并输出相同的结果,但第一个命令花费一些时间,格式也几乎没有差异。
find . -type f -exec file {} \;
find . -type f -exec file {} \+
find . -type f | xargs file
这是因为第1个file命令针对来自该find命令的每个文件运行该命令。因此,基本上它的运行方式为:
file file1.txt
file file2.txt
但是后2个带有-exec命令的find 命令对所有文件运行一次run file命令,如下所示:
file file1.txt file2.txt
然后,我运行以下命令,第一个在没有问题的情况下运行,但是第二个给出错误消息。
find . -type f -iname '*.cpp' -exec mv {} ./test/ \;
find . -type f -iname '*.cpp' -exec mv {} ./test/ \+ #gives error:find: missing argument to `-exec'
对于带有的命令{} \+,它会给我错误消息
find: missing argument to `-exec'
这是为什么?谁能解释我在做什么错?