欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

shell 命令 find

程序员文章站 2022-04-30 17:17:36
...
deal_log.sh


#! /bin/bash
find /home/*/* -maxdepth 4 -regex ".+\(\.log\|catalina\.out\)\(\.[\d\-]*\)?" -exec ./deal_file.sh {} \;
find /opt/logs -type f -regex ".+\.log\(\.[0-9\-]*\)?" -exec ./deal_file.sh {} \;




deal_file.sh

#! /bin/bash
logfile="clean_log.`date +%Y-%m-%d`"
curfile=$1
if ( echo "$curfile" | grep -e '\.log$' -e 'catalina\.out$' > /dev/null ) ;
then
size=`du -h $1 | awk '{ print $1 } '`
echo "" > $1
echo "clean file "$1 "size:" `du -h $1 | awk '{ print $1 } '`" old size:"$size >> $logfile;
else
echo "rm file" $1 `du -h $1 | awk '{ print $1 } '` >> $logfile;
rm -v $1
fi