据我所知,针对指定的测试,每个匹配的文件都会find -tests -execdir <command> '{}' ';'
运行。command
当使用 时,该命令-execdir
在与匹配文件(对于每个匹配文件)相同的父目录中执行,代表{}
匹配文件的基本名称。
现在的问题是:当使用而不是同时处理多个文件时,这是如何完成+
的';'
?如果我使用find -tests -execdir <command> '{}' +
,所有文件都将作为参数提供给指定的命令(以不超过最大参数的方式)。<command>
find 如何同时对所有这些执行?
假设您find
找到以下文件:
./foo/bar\n./foo/baz\n./foo/quux\n
Run Code Online (Sandbox Code Playgroud)\n\n如果您使用-execdir [...]+
,则有效的结果命令将是:
( cd ./foo; command bar baz quux )\n
Run Code Online (Sandbox Code Playgroud)\n\n与(有效)相反,如果您使用-execdir [...] \\;
:
( cd ./foo; command bar )\n( cd ./foo; command baz )\n( cd ./foo; command quux )\n
Run Code Online (Sandbox Code Playgroud)\n\n-exec
not 也是如此,execdir
但它会指定路径而不是更改工作目录。如果您使用-exec [...]+
,则有效的结果命令将是:
command ./foo/bar ./foo/baz ./foo/quux\n
Run Code Online (Sandbox Code Playgroud)\n\n与(有效)相反,如果您使用-exec [...] \\;
:
command ./foo/bar\ncommand ./foo/baz\ncommand ./foo/quux\n
Run Code Online (Sandbox Code Playgroud)\n\n让我们看看在两个目录中找到的文件的行为如何:
\n\n$ tree\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bletch\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 freeble\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 foo\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 baz\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 quux\n$ find . -type f -exec echo {} \\;\n./foo/baz\n./foo/quux\n./foo/bar\n./bar/bletch\n./bar/freeble\n$ find . -type f -execdir echo {} \\;\n./baz\n./quux\n./bar\n./bletch\n./freeble\n$ find . -type f -exec echo {} +\n./foo/baz ./foo/quux ./foo/bar ./bar/bletch ./bar/freeble\n$ find . -type f -execdir echo {} +\n./baz ./quux ./bar\n./bletch ./freeble\n
Run Code Online (Sandbox Code Playgroud)\n