実際には、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あなたが現在していることは、それらを逆方向に配管することです。