Delete Files based on Date

Ed Wilts ewilts at ewilts.org
Wed Mar 30 16:42:39 UTC 2005


On Wed, Mar 30, 2005 at 10:30:23AM -0600, Kelley.Coleman at med.va.gov wrote:
> I'm somewhat hampered by my OpenVMS experience with this problem.  

VMS forever!!! 

> I need a script that will remove all but the latest five files in a
> folder.  There is only one file per day and I want to keep five days
> worth.  

There are couple of options - find and tmpwatch.  Here are some examples:
find /var/log/samba -mtime +5 -exec rm {} \;
tmpwatch 120 /var/log/samba
tmpwatch --nodirs --mtime 120/usr/openv/netbackup/logs/

Both will do what you want. You can look at the various timestamps to
see if you want to base your deletion on created time, modified time, or
access time.

-- 
Ed Wilts, RHCE
Mounds View, MN, USA
mailto:ewilts at ewilts.org
Member #1, Red Hat Community Ambassador Program




More information about the redhat-list mailing list