Tmpwatch is tools that recursively removes files which have not been used or accessed for certain period of time. In this post, i will describe how we can automate the clean up process on log directory on linux CentOS 6.6. You can use tmpwatch to safely remove unwanted files for a given time.
1. How to install tmpwatch package :
[[email protected] ~]# yum install tmpwatch -y
2. As example, delete all logs in /var/log/nginx for more than 30d(30 days).
[[email protected] ~]# /usr/sbin/tmpwatch 30d /var/log/nginx
3. Add the tmpwatch into the cronjob so that we can automate the removal process. As example let the removal task start 10PM every night.
0 22 * * * /usr/sbin/tmpwatch 30d /var/log/nginx