Saturday 16 February 2019

Keep Newest Log files and Purge Files Older than n Runs

The below find command helps you to Keep Newest Log Files and Purge Log Files which is older than n Runs.

This helps us to keep the Directories Clean without keeping older Log files which are no longer required.

# find /var/test/*.log | sort -nr | tail -n +4| xargs rm


 The above command will delete the log files in the /var/test directory which is older than 3 Runs,  Increase the tail -n +(n+1) value to purge the log files greater than n runs.

To Purge log files older than 10 runs #find /var/test/*.log | sort -nr | tail -n +11 | xargs rm




 

No comments:

Post a Comment