Introduction About Site Map

XML
RSS 2 Feed RSS 2 Feed
Navigation

Main Page | Blog Index

Saturday, March 10th, 2012, 12:23 am

Linux/Unix: Deleting Old Files in a Cron Job

SEVERAL years ago I wrote about an old backup procedure of mine. Sometimes people set up a job to make a backup, but what about removing backups that are too old to matter? If a directory/file needs deleting based on age, with wildcards one could run something like:

rm ~/some_file-`date -d "7 day ago" +%d%m%Y`*
rm ~/some_file-`date -d "6 day ago" +%d%m%Y`*

Or quick and dirty (risky if there’s a mixture of files in the said location):

find . -atime +7 -exec rm {} \;;

There’s nothing complicated to it. Once it’s done once, it can be modified thereafter.

Technical Notes About Comments

Comments may include corrections, additions, citations, expressions of consent or even disagreements. They should preferably remain on topic.

Moderation: All genuine comments will be added. If your comment does not appear immediately (a rarity), it awaits moderation as it contained a sensitive word or a URI.

Trackbacks: The URI to TrackBack this entry is:

https://schestowitz.com/Weblog/archives/2012/03/10/deleting-old-stuff/trackback/

Syndication: RSS feed for comments on this post RSS 2

    See also: What are feeds?, Local Feeds

Comments format: Line and paragraph breaks are automatic, E-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Back to top

Retrieval statistics: 21 queries taking a total of 0.166 seconds • Please report low bandwidth using the feedback form
Original styles created by Ian Main (all acknowledgements) • PHP scripts and styles later modified by Roy Schestowitz • Help yourself to a GPL'd copy
|— Proudly powered by W o r d P r e s s — based on a heavily-hacked version 1.2.1 (Mingus) installation —|