クローン作業クリーンアップディレクトリ

クローン作業クリーンアップディレクトリ

クローン操作を使用してフォルダから14日以上経過したファイルを削除するにはどうすればよいですか?今まで試したことはすべてうまくいきませんでした。

ベストアンサー1

このコマンドを簡単に使用できますfind。ディレクトリからこのコマンドを実行しますcrontab(ファイルとサブディレクトリが削除されます)。

find /path/to/target -mtime +14 -delete

~からman find

   -mtime n
          File's data was last modified n*24 hours ago.  

   Numeric arguments can be specified as

   +n     for greater than n,

   -n     for less than n,

   n      for exactly n.


   -delete
          Delete files; true if removal succeeded.  If the removal failed,
          an  error message is issued.  If -delete fails, find's exit sta‐
          tus will be nonzero (when it eventually exits).  Use of  -delete
          automatically turns on the -depth option.

POSIXの認識は不明ですが、検索の実装-deleteが不足している場合にも-delete使用できます。

find /path/to/target -mtime +14 -exec rm {} +

おすすめ記事