Copy Code code as follows:
#!/bin/bash
#Description: Delete Files
#===== defines the current year, the month, and the directory where the file resides =====#
Currentyear= ' Date +%y '
Currentmonth= ' date +%m |awk-f ' 0 ' {print $} '
Videodir=/var/video
#====== defines a transformation function that converts a month abbreviation to a number representation ========#
function Month2num () {
Case $file _month in
.)
File_month=1
;;
FEB)
file_month=2
;;
Mar)
File_month=3
;;
APR)
File_month=4
;;
May)
File_month=5
;;
June)
File_month=6
;;
June)
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
}
#===== defines the previous year as well as the list of all files from previous years =====#
lastyear=$[$currentYear-1]
Lastyearfiles= '/bin/ls-l $videodir/|grep $lastYear |awk-f ' ' {print $} '
#===== deletes previous year's file, today is May 2013, deletes all documents prior to May 2012 (January-April) =====#
For LastFile in ' Echo $lastYearFiles '
Todo
File_month= '/bin/ls-l $videodir/$lastfile |awk-f ' ' {print $} '
Month2num
If [$file _month-lt $currentMonth]
Then
RM-RF $videodir/$lastfile
Fi
Done
#===== Delete all files not in the previous year and not this year =====#
Otheryearfiles= '/bin/ls-l $videodir/|grep-v $lastYear |awk-f ' ' {print $} '
For Otherfile in ' Echo $otherYearFiles '
Todo
file_year_format= '/bin/ls-l $videodir/$otherfile |awk-f ' {print $} ' |wc-c '
If [$file _year_format-eq 5]
Then
RM-RF $videodir/$otherfile
Fi
Done