Article updated on

Cron jobs. Move or delete old files in ubuntu every day. Examples

Go to folder cd /etc/cron.d to create cron jobs that will be run every day. Create a file and write the desired cron sentence.

 

At 1 o'clock AM every day remove from /var/log/*.log files that are at least 7 days old.

0  1    * * *   root    find /var/log/*.log -mtime +7 delete \;

 

At 3 o'clock AM every day move from /var/log/*.log files to /var/log/history

0  3    * * *   root    find /var/log/*.log -mtime +1 -exec mv {} /var/log/history \;

 

Create Folder if It doesn't exists and At 3 o'clock AM every day move from /var/log/*.log files to /var/log/history

0  3    * * *   root    mkdir -p /var/log/MDtel/ivr_historico&&find /var/log/*.log -mtime +1 -exec mv {} /var/log/history \;