在find中使用分号(;)和加号(+) [英] Using semicolon (;) vs plus (+) with exec in find

查看:336
本文介绍了在find中使用分号(;)和加号(+)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在使用

  find的输出之间有差异。 -exec ls'{}'\ + 

  find。 -exec ls'{}'\; 

我得到了:

  $ find。 -exec ls \ {\} \ + 
./file1 ./file2

。:
file1 file2 testdir1

./testdir1 :
testdir2

./testdir1/testdir2:


$ find。 -exec ls \ {\} \;
file1 file2 testdir1
testdir2
./file2
./file1


这可能是最好的例子。假设 find 显示这些文件:

  file1 
file2
file3






使用 -exec 用分号( find。-exec ls'{}'\; )执行

  ls file1 
ls file2
ls file3
find。-exec ls'{}'\ + ),许多文件名尽可能作为参数传递给单个命令:

  ls file1 file2 file3 

文件名的数量只受系统最大命令行长度的限制。如果命令超过这个长度,命令将被多次调用。


Why is there a difference in output between using

find . -exec ls '{}' \+

and

find . -exec ls '{}' \;

I got:

$ find . -exec ls  \{\} \+
./file1  ./file2

.:
file1  file2  testdir1

./testdir1:
testdir2

./testdir1/testdir2:


$ find . -exec ls  \{\} \;
file1  file2  testdir1
testdir2
./file2
./file1

解决方案

This might be best illustrated with an example. Let's say that find turns up these files:

file1
file2
file3


Using -exec with a semicolon (find . -exec ls '{}' \;), will execute

ls file1
ls file2
ls file3

But if you use a plus sign instead (find . -exec ls '{}' \+), as many filenames as possible are passed as arguments to a single command:

ls file1 file2 file3

The number of filenames is only limited by the system's maximum command line length. If the command exceeds this length, the command will be called multiple times.

这篇关于在find中使用分号(;)和加号(+)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆