#!/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