shell 查找目录下最新和最旧文件[时间戳]
#/bin/bashdeclare -a files=(`ls -l | awk '/mysql-bin/ {print $9}'`)
min=${files}
max=${files}
if [ "$min" = "$max" ];then
echo `date +%Y%m%d-%T`'newlog && oldlog is null'>>logfile.txt
exit
fi
for i in `ls -l|awk '/mysql-bin/ {print $9}'`; do
if [ "$max" = "" ];then
echo `date +%Y%m%d-%T`'newlog && oldlog is null='"$min">>logfile.txt
exit
fi
if [ $i -ot $max ];then
max=$i
elif [ $min -ot $i ];then
min=$i
fi
done
echo `date +%Y%m%d-%T`oldlog="$max" newlog="$min" >>logfile.txt
页:
[1]