Delete a file after 3 days

Hi..

Am using diff to compare 2 directories(A & B) and as ouput i get a list of files which are found only in directory B ( I used grep & sed to create the list).

Now I want to delete the files which are found only in dir B after 3 days.
Please help me with this.

Thanks
CoolAtt

You could try to search those files with an appropriate find and a -mtime -3.

I already have the list of files to be deleted.

find as far as i know take a directory as argument. Is it possible to run find on a list of files to calculate their age ?? :confused:

plz advise.thanks

Try this code but then for your directory and change time.
Did you mean something like this?

find /appl/* -type d -ctime +0 -exec rm -rf {} \; 

Maybe you can use first the find so that you get all the files you need that are older than 3 days and do then your diff etc. ie. change the order to sort them out.

find /dirB -type f -mtime +3 | xargs -i rm {}

This will remove the files which is older than 3 days from the dir B

thanks for replies, but i think these will not help.

Lets say I make a backup of a file named xyz.txt on 22-JAN-2010.

On 15-FEB-2010 I delete it.

When I do diff on 15-FEB-2010 , it will say xyz.txt exist only in the backup.
If I calculate its age it will be 23 days old.

I calculate age of file using the following script:

myfile=xyz.txt
tnow=`date +%s`
tfile=`date +%s -r $myfile`
agesecs=$(($tnow-$tfile)) #Age of filename in seconds
agedays=$(($agesecs/86400)) #Age in days

I want to delete the file 3 days after , relative to 15-FEB-2010.
Using the above script if i compare age on 15-FEB-2010 it will already be > 3 days

Please help :frowning:

You can achieve this with then combination of find and crontab command.