【发布时间】:2011-08-02 05:27:52
【问题描述】:
我想确切地知道{} \; 和{} \+ 和| xargs ... 做了什么。请用解释澄清这些。
以下 3 个命令运行并输出相同的结果,但第一个命令需要一点时间,格式也略有不同。
find . -type f -exec file {} \;
find . -type f -exec file {} \+
find . -type f | xargs file
这是因为第一个对来自find 命令的每个文件运行file 命令。所以,基本上它运行为:
file file1.txt
file file2.txt
但后两个 find 使用 -exec 命令对所有文件运行一次文件命令,如下所示:
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'
这是为什么呢?谁能解释一下我做错了什么?
【问题讨论】:
-
真正的问题很简单,为什么第一个有效而第二个无效? (1)找。 -type f -iname '.cpp' -exec mv {} ./test/ \; (2) 找到 。 -type f -iname '.cpp' -exec mv {} ./test/ \+