Linux – How to create a cron job to delete two files every 24 hours

cronlinuxvps

I'm new at hosting my VPS on a CentOS linux server.

The following log files grow quite rapidly and I would like to have them deleted every 24 hours:

/home/httpd/tanguay.info/stats/tanguay.info-custom_log
/home/httpd/tanguay.info/stats/tanguay.info-error_log

/home/admin/__processed_stats/*

What would be the steps for me to create a cron job that deletes all of these files every night at midnight?

Best Answer

It is not recommended to immediately purge logfiles as they may be needed later for debugging, statistics or tracing an intrusion. While log shipping offsite may be overkill in a single VPS scenario, there are better approaches than simply deleting those.

I suggest you look into logrotate or cronolog (Probably available as package on CentOS). With these packages you can set up rules how to process logfiles on a (usually) daily basis, like: Keep a week worth of logs, but compress all of them except today's.

Related Topic