linux删除指定日志文件的通用脚本
#!/bin/sh
#获取删除文件目录
MAIN_DIR="/home/user_shell/"
DELETE_TIME=`date +%Y-%m-%d\ %H:%M:%S`
#获取近五天前日期
TIMESTAMP1=`date +"%Y-%m-%d" -d "-4 days"`
TIMESTAMP2=`date +"%Y-%m-%d" -d "-3 days"`
TIMESTAMP3=`date +"%Y-%m-%d" -d "-2 days"`
TIMESTAMP4=`date +"%Y-%m-%d" -d "-1 days"`
TIMESTAMP5=`date +"%Y-%m-%d"`
#拼凑等下排除删除的参数
DELETE_FILE=${MAIN_DIR}baidu.${TIMESTAMP1}.out"|"${MAIN_DIR}baidu.${TIMESTAMP2}.out"|"${MAIN_DIR}baidu.${TIMESTAMP3}.out"|"${MAIN_DIR}baidu.${TIMESTAMP4}.out"|"${MAIN_DIR}baidu.${TIMESTAMP5}.out
echo ${DELETE_FILE}
sleep 1
rm `ls ${MAIN_DIR}baidu.*|egrep -v "(${DELETE_FILE})"`
sleep 1
#创建本次删除日志
echo "===delete file exclude==="${DELETE_FILE}" delete date:"${DELETE_TIME} >> /data/crontab_shell/rm_logs_for_log.log
标签:-%,baidu,删除,linux,date,日志,MAIN,DIR,DELETE
From: https://blog.csdn.net/hejiefeng111/article/details/142528132