Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete folders that are older than a day? (Cron Job)

I want to delete a folder and its contents on my host if it is over a day old. The issue is that I have no experience on how to do this with a linux cron job. I should also say that i have looked at google and nothing comes up. I think this is a pretty simple question so please, help me out. Thanks

like image 388
Joe Scotto Avatar asked Mar 14 '14 07:03

Joe Scotto


Video Answer


1 Answers

This should do it:

find /path/to/dir -maxdepth 0 -ctime +1 -exec rm -fr {} +

But be careful, and test it first outside of cron, without the -exec part, so you don't delete something else by accident.

like image 182
janos Avatar answered Oct 19 '22 10:10

janos