79.批量刪除日誌文件

#!/bin/bash
#The script is used to batch delete log files.
#Date 2021-01-30
dir1=/tmp/log_test1
dir2=/tmp/log_test2
if [ -d $dir1 ];then#判斷目錄是否存在
        n1=`ls $dir1|wc -l`
        if [ "$n1" -ne 0 ];then#判斷文件是否存在
        find $dir1 -type f -mtime +7 |xargs rm
        fi
fi
if [ -d $dir2 ];then#判斷目錄是否存在
        n2=`ls $dir2|wc -l`
        if [ "$n2" -ne 0 ];thenn#判斷文件是否存在
        find $dir2 -type f -name '*.log' -mtime +15 |xargs rm 2>/dev/null
        fi
fi
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章