rm {} + 起什么作用?

rm {} + 起什么作用?

就像

find -L /etc/ssl/certs/ -type l -exec rm {} +

因此它会找到所有损坏的符号链接并将其删除。但我该如何准确解释这一{} +部分呢?

答案1

{}是命令的占位符exec。 find 找到的任何文件都会插入到括号中。这+意味着建立一个找到的文件的长列表,并一次对所有文件调用 exec,而不是像更传统的-exec {} \;变体那样一次一个地调用。

答案2

man find

   -exec command {} +
   This variant of the -exec option runs the specified  command  on
   the  selected  files, but the command line is built by appending
   each selected file name at the end; the total number of  invoca-
   tions  of  the  command  will  be  much  less than the number of
   matched files.  The command line is built in much the  same  way
   that  xargs builds its command lines.  Only one instance of '{}'
   is allowed within the command.  The command is executed  in  the
   starting directory.

因此它将调用该命令:

rm [filename1] [filename2] [...] [lastfilename]

如果文件数量超出参数列表的容量,rm则会调用多次。(这就是xargs所做的事情。)

如果没有,{} +它只会调用rm很多次而没有任何参数。

相关内容