Purge files based on timestamp avl in file name

Dear All,

I have the followoing requirement..

REQ-1:
Suppose I have the following files
XX_20070202000101.zip
XX_20080223000101.zip
XX_20080226000101.zip
XX_20080227000101.zip
XX_20080228000101.zip
XX_20080229000101.zip

Suppose sysdate [today's date] = 29 Feb 2007
I need to delete all files older than 3 days from current sysdate

After my archival process,
i.e I will retain the files
XX_20080227000101.zip
XX_20080228000101.zip
XX_20080229000101.zip

AND DELETE The fololowing files
XX_20070202000101.zip
XX_20080223000101.zip
XX_20080226000101.zip

In my case , I need to compare the sysdate against the timestamp value which is avaialble in the file name [XX_YYYYMMDDHHMMSS.zip].

Can you please advice on teh same

Regards,
Suresh

Here is a way:

First get the previous two days

# suppose today is 20080229 (date + %Y%m%d)
# then to get two days before you can write

yesterday1=`TZ=$TZ+24 date +%Y%m%d`
yesterday2=`TZ=$TZ+48 date +%Y%m%d`

# Then yesterday1 = 20080228  yesterday2 = 20080227

now you can perform a lot of things like


cp XX_${yesterday1}*.zip 1.zip
cp XX_${yesterday2}*.zip 2.zip

rm XX*

mv 1.zip XX_${yesterday1}*.zip
mv 2.zip XX_${yesterday2}*.zip

hope you get the point :slight_smile:

Hey ..

Thanks for the info
but in my development box

Both the commands below are showing the same results..can you please advice

comadm@czhs0255 /home/comadm/test
TZ=$TZ+48 date +%Y%m%d
20080229
comadm@czhs0255 /home/comadm/test
TZ=$TZ+24 date +%Y%m%d
20080229

Regards,
Suresh

find /home/comadm/test -ctime +3 -exec rm -f {} \;