LoginSignup
2
2

More than 5 years have passed since last update.

指定した日付以前に作成されたファイルを一括で削除するコマンド

Last updated at Posted at 2014-05-13

アプリケーションログなどが溜まってディスク容量を逼迫している場合に便利です。

例)90日より前に作成されたログファイルを削除する

find /export/httpd/hogehoge/logs -maxdepth 1 -type f -mtime +90 -regex ".*/logs/.*\.log" | xargs rm -f

下記のようにcronを仕込んでおくと便利です。

# 毎日0時10分に、3ヶ月以前のアプリケーションログを削除
10 0 * * * /usr/bin/find /export/httpd/hogehoge/logs -maxdepth 1 -type f -mtime +90 -regex ".*/logs/.*\.log" | /usr/bin/xargs /bin/rm -f

※tmpwatch使えよとか言わないの...

2
2
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
2
2