shell脚本--清除几天前的日志文件或备份文件
上一篇 /
下一篇 2018-12-27 12:40:34
/ 个人分类:总结
清除7天前的日志文件或备份文件
#!/bin/bash
UEEP_PUTFILE_DIR=/home/aaa/log/current
BAK_DIR=/home/aaa/data/backup
#clear date 7天前
ONE_WEEK_AGO=`date "+%Y%m%d" -d "7 day ago"`
echo ' begin to delete logs and backup one week ago '
#clear logs
#echo " $UEEP_PUTFILE_DIR/*$ONE_WEEK_AGO"
rm -f $UFEP_PUTFILE_DIR/*$ONE_WEEK_AGO
echo 'delete $ONE_WEEK_AGO logs finished!'
#clear backup files
rm -f $BAK_DIR/*/*$ONE_WEEK_AGO*
echo 'delete $ONE_WEEK_AGO backup files finished!'
或者
#!/bin/bash
UEEP_PUTFILE_DIR=/home/bs/log/current
BAK_DIR=/home/bs/data/backup/*/
#delete files on /home/ex/log/current folder before 7 days
find $UEEP_PUTFILE_DIR -mtime +7 -type f|xargs rm -f
find $BAK_DIR -mtime +7 -type f|xargs rm -f
收藏
举报
TAG: