Time Difference between two files in two different directories

Hi,

Can anyone please help me.
How to write shell script for taking time difference between two files which are in two different folders.

Example:

Folder1 is having sample_1_.txt with the time 13:10 hours
Folder2 is having sample_1_
.txt with the time 13:17 hours

Now i need the time difference between many files like this by running a shell script. I need the output as below

Folder1 Folder2 Time Diff
sample_1_ sample_2_ 7 Seconds

This script is very urgent for me. Anyone's help is honestly appreciated.

Regards,
Sanjay...

What OS are you running?

Try something like below which uses epoch time to calculate the time diff:

file1_time=$(date +%s -d"$( ls -l file1 | awk ' { print $(NF-3)" "$(NF-2)" "$(NF-1); }')")
file2_time=$(date +%s -d"$( ls -l file1 | awk ' { print $(NF-3)" "$(NF-2)" "$(NF-1); }')")
(( diff_time =  file2_time - file1_time ))
echo $diff_time

First, show the last modification time for each file

> ls -l master.fmt
-rwxrwx--- 1 user xx 658 Sep  2 07:09 master.fmt*
> ls -l wor20080914.fmt
-rw-rw---- 1 user xx 219 Sep 15 11:01 wor20080914.fmt

Then, do stat commands on each file, and subtract one from the other.

> echo `stat -c%Y wor20080914.fmt` - `stat -c%Y master.fmt` | bc
1137073

You could divide by 60 to learn the # minutes
Divide again by 60 to learn # hours
And divide by 24 to learn the # days == 13.16

stat assumes GNU tools. Not everyone has those. Just so you guys are aware of this.
Not that stat is a bad choice, it is great if you have it.

OS is AIX

AIX has an alternative: the istat command.

Regards