您实际上是将管道rm的输出传递到的输入find。你想要的是使用的输出find作为参数来rm:
find -type f -name '*.sql' -mtime +15 | xargs rm
xargs是将其标准输入“转换”为另一个程序的参数的命令,或者更准确地说,是将其输入到man页面上的命令,
从标准输入构建和执行命令行
请注意,如果文件名可以包含空格字符,则应对此进行更正:
find -type f -name '*.sql' -mtime +15 -print0 | xargs -0 rm
但实际上,find有一个快捷方式:-delete选项:
find -type f -name '*.sql' -mtime +15 -delete
请注意以下警告man find:
Warnings: Don't forget that the find command line is evaluated
as an expression, so putting -delete first will make find try to
delete everything below the starting points you specified. When
testing a find command line that you later intend to use with
-delete, you should explicitly specify -depth in order to avoid
later surprises. Because -delete implies -depth, you cannot
usefully use -prune and -delete together.
PS请注意,直接管道到rm这不是一个选择,因为rm在标准输入中不希望使用文件名。您当前正在做的是将它们反向传送。