Top/Linux/シェルスクリプト/n日以上前に作成されたファイルを削除する

Linux/シェルスクリプト/n日以上前に作成されたファイルを削除する のバックアップの現在との差分(No.1)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
**参考URL [#v0301071]
http://sonic64.com/2003-04-16.html
以下のようなコマンドで手軽に数日以上前に作成したファイルを削除できます。

**シェル例 [#g845041b]
 (例)
 find /home/postgres/dbbackup -type f -daystart -mtime +n |xargs /bin/rm -f
find (場所) -type f -daystart -mtime +n |xargs /bin/rm -f
上記の-mtime +n の n に日数を指定できます。
cron を使って毎日実行すれば、毎日ディレクトリを監視して一定期間を過ぎたファイルを消す、という使い方ができます。

 (作成したスクリプト)kuro-box:/mnt/share/p2p/cacheanime
(シェル例)
 #!/bin/sh
 find . -type f -daystart -mtime +15 |xargs /bin/rm -f
 find /usr/local/tomcat/logs -type f -daystart -mtime +15 |xargs /bin/rm -f

-参考URL:Landscape - エンジニアのメモ
--http://sonic64.com/2003-04-16.html

ページ新規作成

新しいページはこちらから投稿できます。

TOP