Merging duplicate files in two dir

Hi,

I have duplicate files in 2 directories

/mainfolder1/folder/abc.txt (say with date 1-Apr-08)
/mainfolder2/folder/abc.txt (say with date 20-Oct-03)

I would like to merge/consolidate the two directories and get retain the file with the latest timestamp:

/mainfolder3/folder/abc.txt (with date 1-Apr-08).

How can I do this via a Shell script?

Regards,
Desperate for help :smiley:

do you mean to say if the filenames are same then delete the older file and keep the newer file in the new location?

Yes...and the files can be in multiple depths:

47 Apr 1 08 /mainfolder1/folder/abc.txt
1122 Oct 20 03 /mainfolder2/folder1/subdir/abc.txt
456 May 2 08 /mainfolder1/folder/def.txt
2200 Oct 22 03 /mainfolder3/folder2/subdir/def.txt

Ideally before the deletion is performed, I would like to be able to generate the above file (or something similar) which shows the file size, file name and full path and timestamp.

Use rsync

I think this may create an error if the same filename exists in two different folders and is used for two different purposes.Be cautious.