#!/bin/bash
# Deletes all but the newest 5 files to keep Tokyo Tyrant ulogs from diractor
#==================================
#
#Author: guolimin
#
#Email: guolimin1118@163.com#
#Data: 2009.10.01
#
# Http://accepting.sharera.com
#DOWNLOADS="/home/medialib/download"
#==================================
logdir="/home/tsaip/guolimin/"
mydir=`ls -t $logdir|grep ulog`
count=`ls -l|grep ulog|wc -l`
end=$((count-5))
it=0
for file in $mydir
do
if [ $it -gt $end ]
then
echo file $it will be deleted: $logdir$file
rm -rf $file
fi
it=$((it+1))
done
第二种通过find操作更加简单
find /opt/ibm/logs -ctime +6 -name "*msgflow_info.log*" -exec rm -rf {} /;
ps:http://blog.vfocus.net/archives/000380.html
http://hi.baidu.com/istang/blog/item/0a01191257b6dc5df919b855.html