
February 19th, 2011, 09:13 PM
|
|
|
If it is based purely on the filename then your best bet is a script that constructs a date comparison variable in form yyyymmdd based on current date, with 1 subtracted from the year (much like the date pattern in the filenames you have, which is handy!) and treat it as a plain number, comparing the date part of the file names to your comparison variable.
One way to do that is, assuming you are in the correct directory (not tested!):
Code:
yr=$(date "+%Y")
yr=$(( yr - 1 ))
mmdd=$(date "+%md")
a_year_ago="$yr$mmdd"
for file in $(ls -1)
do
date_part=$(echo $file | awk -F_ '{print $2}')
if [ $date -lt $a_year_ago ]
then
echo "Deleting file $file as it is over a year old"
fi
done
If it can be based on last modification date then a find using the -mtime +365 option will list files not modified for over a year.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|