To delete more than the number of days of log files or backup files

First, delete log files more than 7 days

  Server log files need to be generated in some production environments regular deletion, because the log file over time, will take up a lot of space record, but some log files are not necessary to keep for a long time, so you need to be deleted, but If you manually delete it, the workload is relatively large, so the combination of scheduled tasks can regularly delete the log files with scripts, here to log more than seven days, for example, generally used to delete the backup files, because the backup could be every day generation, those over a certain date there is no need of a backup file has been saved and can be deleted. But some production environments require a permanent hold no other way.

1.1, prepare some log files and regular files in a directory

 

 1.2, delete modify the script for more than seven days file

! # / bin / bash
 the Find / the Test / logs / -name " * .log " -mtime + 7 -exec RM -f {} \; # find the log directory of more than seven days in a ".log" at the end of the log file and delete

 

 1.3, create a scheduled task designated to periodically delete the log

 

 1.4, verify the removal of more than seven days of log

 

 

Guess you like

Origin www.cnblogs.com/mython/p/11910809.html