cancel
Showing results for 
Search instead for 
Did you mean: 

Remove older than 2 weeks

SOLVED
Go to solution
Qcheck
Super Advisor

Remove older than 2 weeks

How can I schedule the cron job where it purges the /tmp directory files older than two weeks?

Thanks
5 REPLIES
Oviwan
Honored Contributor
Solution

Re: Remove older than 2 weeks

Hey

something like that:
find /tmp -mtime +14 -exec rm {}\;

Regards
James R. Ferguson
Acclaimed Contributor

Re: Remove older than 2 weeks

Hi:

Run this :

# find /tmp -type f -mtime +14 -exec rm {} \;

This will remove *files* from the '/tmp' directory that are older than 14-days based upon their last-modified timestamp ('mtime').

To create a crontab entry to run at 23:30 hours every day, add this to your crontab:

# 30 23 * * * find /tmp -type f -mtime +14 -exec rm {} \;

Regards!

...JRF...
Qcheck
Super Advisor

Re: Remove older than 2 weeks

Thank you James and owivan... I really appreciate your help. I just setup in cron. Thanks again.
Stuart Browne
Honored Contributor

Re: Remove older than 2 weeks

You might also want to see if your system is already running a scheduled job called 'tmpwatch'.

On a Redhat system, this is run from '/etc/cron.daily/tmpwatch', and has a line similar to this in it:

/usr/sbin/tmpwatch 240 /tmp

(Note: It may have some '-x ' excludes on it to ignore X windows sockets).

This does basically what you are after, but for files older than 10 days. Tweaking 240 down to 48 would also do what you are after.
One long-haired git at your service...
Stuart Browne
Honored Contributor

Re: Remove older than 2 weeks

Oops, not down to 48.. Up it to 336..
One long-haired git at your service...