Directly on the code
↓
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 command _Linux find command usage Detailed: Find files in the specified directory
https://man.linuxde.net/find
Virtual machine experiment
↓
Found lower than 1MB file, gzip compression labeled packet, the source files gone
find / var / log / -type f -size + 1M -print -exec gzip {} \;
The "* .gz" compressed file, batch rename "* .190827.gz" in the form of compressed source file, there is no
find / var / log / -type f -iname "* .gz" | xargs rename .gz .`date "+% Y% m % d" `.gz
Calculated from the date of this find, modified 3 days ago "* .gz" file, delete the
find / var / log / -type f -daystart -mtime +3 -iname "* .gz" -print -exec rm -f {} \;