LoginSignup
36
37

More than 5 years have passed since last update.

Linux - n日前・n分前のファイルを削除する方法

Posted at

今更ながらfindコマンドでn日前・n分前のファイルを削除する方法をメモ

1.findコマンドのフォーマット

find [path..] [expression]

2.日時を指定するオプション

  • -atime +n

    最終アクセス日時がn日以前のfile(or directory)を検索

  • -atime -n

    最終アクセス日時がn日以降のfile(or directory)を検索

  • -ctime +n

    最終変更日時がn日以前のfile(or directory)を検索

※「+」はn日以前、「-」はn日以降、ない場合はn日前

※「-amin」「-cmin」「-mmin」だとn分前を指定できる

3.アクション指定するオプション

--exec [command] {} \;
  • 30日以前のファイルを表示
find ./ -mtime 30 -exec ls -l {} \;
  • 30日以前のファイルを削除
find ./ -mtime 30 -exec rm -f {} \;

参考

36
37
1

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
36
37