#!/bin/bash
#!/bin/bash
#exact all log files
#计算log文件个数
log_number=`ls *.log |grep log -c`
#当log文件数大于0时遍历删除文件中的文件夹
if [ $log_number -gt 0 ];then
list_log_files=$(ls *.log)
#Traverse to delete files
for log_file in $list_log_files
do
#delete all log files
rm -rf $log_file
log_file_number=`ls |grep $log_file -c`
if [ $log_file_number -eq 0 ];then
echo "delete $log_file successfully"
else
echo "delete $log_file failed"
fi
done
fi
log_number=`ls *log.* |grep log -c`
echo $log_number
if [ $log_number -gt 0 ];then
list_log_text=$(ls *log.*)
for log_text in $list_log_text
do
rm -rf $log_text
log_file_number=`ls |grep $log_text -c`
if [ $log_file_number -eq 0 ];then
echo "delete $log_text successfully"
else
echo "delete $log_text failed"
fi
done
fi
原文地址:https://www.cnblogs.com/robert-zhang/p/9144537.html