2015-10-12 18 views
10

Ho usato il comando seguente per cancellare i file più vecchi di un anno.Elimina file più vecchi della data specifica in linux

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

Ma, ora voglio eliminare tutti i file il cui tempo è modificata vecchio diverso da 01 gen 2014

Come faccio lo faccio in Linux.

risposta

13

È possibile toccare il timestamp come un file e utilizzarlo come punto di riferimento:

esempio per 01-gen-2014:

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

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

questo funziona perché find ha un interruttore -newer che stiamo usando.

Da 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

Grazie. ! è buono come -not "find. -not -newer/tmp/2014-gen-01-0000" – VRK

+0

@VRK sì! anche questo è più pulito –

5

questo funziona per me:

find /path ! -newermt "YYYY-MM-DD HH:MM:SS" | xargs rm -rf 
Problemi correlati