How to remove files in a directory on Cron?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


16 points

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?



2 points

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/*

Anonymous's picture
Created by Anonymous
-1 points

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

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.