I have a requirement like following:
I have two dir: DIR1 and DIR2. Files of DIR1 are updated on a regular basis based on requirement. Then updated files are copied to DIR2. So I need to write a shell script which will tell us whether all the files in DIR2 are the updated files or not. This is to make sure that all required files were copied properly from DIR1 to DIR2.
Can anyone please help me how I'll compare the timestamp of a file between the 2 directories.
/home/user/DIR1]ls -l
-rwxrwxr-x 1 user group 509 Jan 08 2009 file_1.dat
-rwxrwxr-x 1 user group 11 Sep 29 12:19 file_2.dat
/home/user/DIR2]ls -l
-rwxrwxr-x 1 user group 509 Jan 08 2008 file_1.dat
-rwxrwxr-x 1 user group 40 Oct 21 12:19 file_2.dat
Thanks & Regards,
Prasenjit
Best Answer
I think the best approach here is to look at how you are actually updating the files in DIR2. Rather than comparing them afterwards, use a tool like
rsync
to do the copy. For example, inrsync
you can run this command:This will copy all files that are newer in dir1 to dir2 and delete any files which no longer exist in dir1. Basically it's a reliable folder "update" without wasting the time of copying files which are already up to date.