Linux系统为/var/spool/mail/目录设置logrotate

直接上代码

1 #!/bin/sh
2 
3 find /var/spool/mail/ -type f -size +10M -print -exec gzip {} \; > /tmp/mail_rotate_gzip.log 2>&1
4 find /var/spool/mail/ -type f -iname *.gz | xargs rename .gz .`date "+%Y%m%d"`.gz
5 find /var/spool/mail/ -type f -daystart -mtime +180 -iname *.gz -print -exec rm -f {} \; > /tmp/mail_rotate_remove.log 2>&1

find命令_Linux find 命令用法详解:在指定目录下查找文件
https://man.linuxde.net/find

虚拟机实验

找到下超过1MB的文件,gzip打成压缩包,源文件就没了
find /var/log/ -type f -size +1M -print -exec gzip {} \;


把"*.gz"压缩包文件,批量重命名为"*.190827.gz"的形式,源压缩包文件就没有了
find /var/log/ -type f -iname "*.gz" | xargs rename .gz .`date "+%Y%m%d"`.gz


找到从本日开始计算,3天前修改过的"*.gz"文件,删除掉
find /var/log/ -type f -daystart -mtime +3 -iname "*.gz" -print -exec rm -f {} \;

猜你喜欢

转载自www.cnblogs.com/tobyhan/p/11419055.html