2015-10-12 8 views
10

私は1年以上古いファイルを削除するために以下のコマンドを使いました。linuxの特定の日付より古いファイルを削除する

find /path/* -mtime +365 -exec rm -rf {} \; 

しかし、今私は、その変更された時間、私は、Linuxでそれを行うにはどうすればよい2014年1月

よりも古い01であるすべてのファイルを削除したいです。

答えて

13

あなたはファイルとしてタイムスタンプを触れると基準点としてそれを使用することができます

例えば01-JAN-2014用:findは、私たちが使用している-newerスイッチを持っているので、

touch -t 201401010000 /tmp/2014-Jan-01-0000 

find /path -type f ! -newer /tmp/2014-Jan-01-0000 | xargs rm -rf 

これは動作します。 man findから

-newer file 
     File was modified more recently than file. If file is a symbolic 
     link and the -H option or the -L option is in effect, the modification time of the 
     file it points to is always used. 
+2

ありがとうございました。 ! -not -newer/tmp/2014-Jan-01-0000 "と同じくらい良いです。 – VRK

+0

@VRK yep!それもクリーナーです –

5

これが私の作品:

find /path ! -newermt "YYYY-MM-DD HH:MM:SS" | xargs rm -rf 
関連する問題