Script to Clear log files more than 5 days and scheduled on daily execution

15 viewsLinux

Log files consuming high disk space, hence  required an automated script to delete the log files greater than  5 days and schedule  to execute on everyday 12:00 AM

Script to delete  files greater than  5 days :-

find $PATH -type f -mtime +5 -exec ls -l {} ; –> list the files greater than 5 days

find $PATH -type f -mtime +5 -exec rm {} ; –> delete the files greater than [be carefull before deleting files, never try to search and delete from OS filesystems]

eg : find /tmp -type f -mtime +5 -exec rm {} ;


To execute the script on everyday 12 AM,  schedule the job in cron.


00 00 * * * find /tmp -type f -mtime +5 -exec rm {} ;

Edited question