如
find -L /etc/ssl/certs/ -type l -exec rm {} +
Run Code Online (Sandbox Code Playgroud)
所以它会找到所有损坏的符号链接并删除它们。但我究竟如何解释这{} +部分?
Ben*_*n S 12
来自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.
Run Code Online (Sandbox Code Playgroud)
所以它会调用命令:
rm [filename1] [filename2] [...] [lastfilename]
Run Code Online (Sandbox Code Playgroud)
如果文件多于无法放入参数列表,rm则将多次调用。(这就是这样xargs做的。)
如果没有{} +它,它只会不rm带参数地调用很多次。
该{}位是exec命令的占位符。find 找到的任何文件都插入到括号的位置。该+方法建立在找到的文件的一个长长的清单,并呼吁所有的人的高管在一次,而不是一次一个,喜欢比较传统的-exec {} \;变种。