#!/bin/bash
#description: delete files
#=====定义当前年份,月份以及文件所在目录=====#
currentyear=`date +%y`
currentmonth=`date +%m |awk -f'0' '{print $2}'`
videodir=/var/video
#======定义一个转换函数,用于将月份缩写转换为数字表示========#
function month2num(){
case $file_month in
jan)
file_month=1
;;
feb)
file_month=2
;;
mar)
file_month=3
;;
apr)
file_month=4
;;
may)
file_month=5
;;
jun)
file_month=6
;;
jul)
file_month=7
;;
aug)
file_month=8
;;
sep)
file_month=9
;;
oct)
file_month=10
;;
nov)
file_month=11
;;
dec)
file_month=12
;;
*)
echo "oh,are you kidding me?!"
exit 1
;;
esac
}
#=====定义上一年年份以及上一年的所有文件列表=====#
lastyear=$[$currentyear-1]
lastyearfiles=`/bin/ls -l $videodir/ |grep $lastyear |awk -f' ' '{print $9}'`
#===== 删除上一年的文件,今天为2013年5月,则删除2012年5月之前的所有文件(1-4月)=====#
for lastfile in `echo $lastyearfiles`
do
file_month=`/bin/ls -l $videodir/$lastfile |awk -f' ' '{print $6}'`
month2num
if [ $file_month -lt $currentmonth ]
then
rm -rf $videodir/$lastfile
fi
done
#=====删除非上一年以及非今年的所有文件=====#
otheryearfiles=`/bin/ls -l $videodir/ |grep -v $lastyear |awk -f' ' '{print $9}'`
for otherfile in `echo $otheryearfiles`
do
file_year_format=`/bin/ls -l $videodir/$otherfile |awk -f' ' '{print $8}'|wc -c`
if [ $file_year_format -eq 5 ]
then
rm -rf $videodir/$otherfile
fi
done
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
嵌入式学习经历帖
随着科技的进步,全凭机械结构完成各种运动的时代已经渐行渐远,不过我仍然对于之前创造的各种运动机构着迷。现在技术的...
[阅读全文]
-
-
-
-
-
-
-
7.27
string底层实现,channel底层实现,redis分布式锁实现, redis的SETNX方法。幂等,cap...
[阅读全文]
网友评论