find /path/to/files* -mtime +30 -exec rm {} \;

Ich mag Einzeiler... ;-)



Twitter Bookmark Delete Files older than 30 days on Linux  at del.icio.us Facebook Google Bookmarks Digg Delete Files older than 30 days on Linux Bookmark Delete Files older than 30 days on Linux  at YahooMyWeb Bookmark Delete Files older than 30 days on Linux  at Furl.net wong it! Identi.ca

Trackbacks


Trackback specific URI for this entry
    No Trackbacks

Comments


    #1 Uli on 06/25/10 at 09:38 PM [Reply]

    find /path/to/files* -type f -mtime +30 | xargs rm

    Ohne -type haust alles in die Tonne wenn das Verzeichnis sich geändert hat, dann findet der find nämlich auch "." ...

    testen würd ich das mit -exec ls -la {} \; oder | xargs ls -la statt mit rm ;-)

    #2 Marc on 06/26/10 at 11:19 AM [Reply]

    Hallo Marco,

    zwei Anmerkungen dazu...

    - Das funktioniert auch mit Dateinamen, die Leerzeichen enthalten, wenn man den Platzhalter für den Dateinamen in Anführungszeichen setzt: -exec rm "{}" \;

    - Bei einer großen Zahl von zu löschenden Dateien gehts mit xargs deutlich billiger/schneller: find /pfad -mtime +30 | xargs rm

    scnr,

    Marc

    #2.1 Marco Gabriel on 07/12/10 at 10:46 PM [Reply]

    danke für deine ergänzungen. xargs allerdings funktioniert bei mir mit vielen dateien eher nicht. ich erinnere mich an einige fälle, bei denen ich mehrere zehntausend dateien damit löschen wollte und es mit xargs nicht schaffte, mit find direkt jedoch schon.

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
BBCode format allowed

   

tweetbackcheck