2016-07-13 7 views
-1

Ich habe viele Beispiele für das Löschen von n Tagen alten Dateien in Linux gesehen, aber keiner von ihnen funktioniert für mich. Im Folgenden sind einige Befehle, die ichSo löschen Sie 1 Tag alte Dateien in Linux

verwendet
[[email protected] dmp]# find . -mtime +1 -exec rm -Rf -- {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# find . -name "*.dmp*" -ctime +1 -exec rm {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# echo find . * -type f -mtime +1 -exec rm {} \; 
find . GSW-11-07-2016.dmp GSW-12-07-2016.dmp GSW-13-07-2016.dmp MI-11-07-2016.dmp MI-12-07-2016.dmp MI-13-07-2016.dmp -type f -mtime +1 -exec rm {} ; 
[[email protected] dmp]# find . * -type f -mtime +1 -exec rm {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# find . * -mtime +1 -exec rm {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# find . * -type f -mtime +1 -exec rm {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# find . * -mtime +1 -exec rm -Rf -- {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# find . -type f -mtime +1 -name '*.dmp' -execdir rm -- {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# find . -type f -ctime +1 -name '*.dmp' -execdir rm -- {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 
[[email protected] dmp]# find . -type f -mtime +1 -name '*.dmp' -print0 | xargs -r0 rm -- 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 11 21:01 GSW-11-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 12 02:30 GSW-12-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 13 02:30 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 11 21:01 MI-11-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 12 02:31 MI-12-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 02:30 MI-13-07-2016.dmp 

2) Ich versuche, auch alte Dateien vom FTP-Remote-Server zu löschen und habe meine Frage hier https://stackoverflow.com/questions/38309645/linux-script-to-delete-ndays-old-ftp-files

UPDATE:
ich die Antwort versucht, aber noch kein Glück

[[email protected] dmp]# find . -type f -mtime +1 -exec rm -rf {} \; 
[[email protected] dmp]# ll 
total 3259164 
-rw-r----- 1 oracle dba 12754944 Jul 13 17:16 GSW-13-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 14 02:30 GSW-14-07-2016.dmp 
-rw-r----- 1 oracle dba 12754944 Jul 15 02:30 GSW-15-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 13 17:16 MI-13-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 14 02:30 MI-14-07-2016.dmp 
-rw-r----- 1 oracle dba 1099702272 Jul 15 02:30 MI-15-07-2016.dmp 
[[email protected] dmp]# 

Bitte beraten, wie kann ich es beheben. Dank im Voraus

+2

Möchten Sie die Dateien aufgelistet ist, wenn Sie 'statt' rm' ls' angeben? – choroba

+0

Abstimmung für 'ls' Idee statt' rm' – LifeSaver

+0

* Abstimmung für 'ls' Idee statt' rm' *, cool, also welches Ergebnis haben Sie bekommen? War es erwartet (Sie haben die Namen der Dateien gesehen, die Sie löschen möchten)? Ich habe es gerade versucht. -mtime +1 -exec rm -Rf - {} \; 'und es hat gut für mich funktioniert. – lurker

Antwort

0

Versuchen:

find . -type f -mtime +1 -exec rm -rf {} \; 
+0

Ja ich habe diesen Befehl schon ausprobiert – LifeSaver

+0

Warum '-rf' zum Löschen von Dateien? Und wenn OP nur Dateien löschen möchte, würde ich "-type f" hinzufügen, um sicher zu sein, dass es keine Verzeichnisse entfernt. – Marki555

+0

@ Marki555 - Ich habe den '-Typ'-Vorschlag hinzugefügt, da ich denke, dass es eine gute Idee wäre. Das OP erwähnt nie etwas über rekursive und erzwungene Löschungen, aber die Beispiele zeigen, dass es verwendet wird, wenn auch mit dem "-R". Also behielt ich das '-rf' auf der Grundlage dessen, was ich aus den Beispielen des OP entnehmen kann. Vielen Dank. – tale852150

Verwandte Themen