Bus errorとSegmentation faultに困ったら見るブログ

物理の研究者による日々の研究生活のメモ書きです ( python/emacs/html/Japascript/シェルスクリプト/TeX/Mac/C言語/Linux/git/tmux/R/ポケモンGO)

ファイル最終更新日がある日時よりも古いファイルを削除したい【シェルコマンド】

使うときは path to dir を自分の環境のものに置き換えてください

7日より古い通常ファイルを再帰削除

find /path/to/dir -type f -mtime +7 -print    # ドライラン
find /path/to/dir -type f -mtime +7 -delete   # 実行

ある“日時”より古い

# 例: 2025-10-01 00:00 以前
find /path/to/dir -type f ! -newermt "2025-10-01 00:00" -print
find /path/to/dir -type f ! -newermt "2025-10-01 00:00" -delete

ランキング参加中です

↓クリックしていただけると嬉しいです〜