问题描述
有了这组命令,{}
和 ;
字符是干什么用的?
With this set of commands, what are the {}
and ;
characters for?
find . -name '*.clj' -exec grep -r resources {} ;
推荐答案
参见 man找到.(特别是关于-exec
的部分)
See man find. (particular the part about -exec
)
当使用 -exec
对找到的每个文件运行命令时,{}
被替换为找到的每个文件的名称,并终止命令by ;
When using -exec
to run a command on each of the files found, the {}
is replaced with the name of each file found, and the command is terminated by ;
在您的示例中,在当前目录 (.
) 下找到的所有文件,匹配名称 *.clj
将具有命令 grep -r resources
对它们运行(查找字符串 resources
如果它存在于每个文件中).
In your example, all files found under the current directory (.
), matching the name *.clj
will have the command grep -r resources
run on them (to find the string resources
if it exists in each of those files).
它实际上有点多余,因为 -r
用于递归搜索子目录,而这正是 find
已经在做的.
It's actually somewhat redundant, since -r
is for recursively searching subdirectories, and that's what find
is already doing.
这篇关于Unix find 命令,什么是{}和;为了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!