How to remove files in a directory on Cron?



I have a certain directory I want to delete files from on Cron run every hour. I am running Ubuntu. Please suggest what to do?



To run a cron every hour, you need to do something like this on your 'crontab -e' editor:

0 * * * * script-to-executed

To remove files from the directory, do following:

0 * * * * rm -rf /var/log/*

You can write a shell script remove-files.sh as follows:

#!/bin/sh
 
rm -rf /home/gamekick/public_html/cache/* 
find /home/gamekick/public_html/cache/ -ctime 1 -exec rm -f {} \;

And run this on cron hourly:

0 * * * * /home/test/remove-files.sh