使用“-exec rm -f {}”时“查找:’-exec’缺少参数”
我运行这个命令:
~/shell_temp$ find . -type f -name "IMAG1806.jpg" -exec rm -f {}\
我得到以下输出:
> IMAG1806.jpg Error: find: missing argument to `-exec'
什么是从当前目录中查找任何文件并使用-exec
删除的确切命令?
你错过了一个;
最后(以及{}
和;
之间的空间)。 正确的命令是:
find . -type f -name "IMAG1806.jpg" -exec rm -f {} \;
;
表示find
的-exec
谓词的结尾。
还要注意我们用过的\;
即\
前面;
逃避解释;
通过shell,否则shell会对待;
作为整个find
命令的结束并且find
会抛出相同的错误。 你也可以用';'
而不是\;
。
您最后使用\
,这表示您的shell将继续通过PS2
(由>
表示)输入,您再次键入IMAG1806.jpg
,因此整个命令变为:
find . -type f -name "IMAG1806.jpg" -exec rm -f {}IMAG1806.jpg
正如你所看到的IMAG1806.jpg
,最后IMAG1806.jpg
根本不是一个有效的命令,没有关闭-exec
谓词而{}
和\;
之间没有空格\;
。
你可以简单
find . -type f -name 'IMAGE1806.jpg' -delete
从手册页:
Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit sta‐ tus will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.