LoginSignup
7
5

More than 5 years have passed since last update.

一定期間過ぎたファイルを自動削除(find -deleteオプション)

Posted at

古いログファイルを簡単に削除したいとき

find コマンドでできます。
こちらのように、find + xargs というのが多いのかもしれませんが、-delete オプションを使っても一発です。

find /path/to/log -name '*.log' -mtime +7 -delete

日数指定のところは以下をご参考に。
findコマンドのmtimeオプションまとめ
findコマンドのmtimeオプションについて

これをcronに設定しておけばOKです。
※OS依存(BSD系?)の模様。

参考

【linux】蓄積されていくログファイルなどを定期的に削除する例
find の -delete オプション

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5