Help - Search - Members - Calendar
Full Version: Daily cleanup
Invision Power Services > Community Forums > Community Web Design and Coding
Fszone
Is there any way via a cron, or a script that I can make it delete all files in x directory daily?
Wombat
CODE
<mins>      <hr>      *      *      *      rm -f /path/to/directory      >/dev/null 2>&1


Add that to your crontab file replacing <mins> and <hr> with the minutes past the hour you want to action to occur. i.e. 0 5 would make the command execute at 5am every day. 0 20 would make the command execute at 8pm every day.

>/dev/null 2>&1 prevents cron from sending an email to your user mailbox each time the command is executed.
Fszone
Could I make it 0 0 and make it execute at midnight? And is there a way to make it so it doesn't delete certain files, such as a .htaccess file?

Thanks a ton for your help.
Wombat
QUOTE(fox666 @ Jul 13 2005, 07:02 PM) *
Could I make it 0 0 and make it execute at midnight? And is there a way to make it so it doesn't delete certain files, such as a .htaccess file?

Thanks a ton for your help.


Yep, that is fine.

As for not deleting certain files... the command I gave can't do that. However you can write a script in your language of choice to perform the deletion of files and then add the path to the crontab entry.

e.g. /path/to/php /path/to/delete-script.php
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.