LoginSignup
0
0

More than 5 years have passed since last update.

findコマンドで更新時間が30日前のファイルを削除する

Posted at

GNU系のfindコマンドの話です。

# カレントディレクトリ内に存在する全てのファイルから、30日前のファイルを表示
find ./ -mtime +30 -type f

# カレントディレクトリ内に存在する全てのファイルから、30日前のファイルをrmコマンドで削除
find ./ -mtime +30 -type f -exec rm {} \;

もちろん、カレントディレクトリの部分は好きに置き換えられます。 /var/log とか。

なお、+-を間違えて顔面ブルースクリーンになる事例もありましたので、
必ず -exec rm {} \; を外して1度試し打ちしてから実行しましょう。

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