user3044691
user3044691

Reputation: 69

know the execution time and compare execution time of 2 files using PERL or shell script

i have to compare the last executed times of two files using perl or shell script

file1.txt  22:07 20-12-13
file2.txt  22:30 21-12-14

Want to compare which one executed latest

Please Help

Thanks in advance

Upvotes: 0

Views: 98

Answers (2)

mpapec
mpapec

Reputation: 50637

perl -le '@r=@ARGV; print $r[-M $r[0] > -M $r[1]]' file1.txt file2.txt

Upvotes: 1

choroba
choroba

Reputation: 241828

What exactly do you mean by "last executed times"? My answer works with the last modification time:

In shell, you can use the -nt and -ot tests:

if [ "$file1" -nt "$file2" ] ; then
    echo "$file1 is newer than $file2."
fi

In Perl, use the -M file test:

if (-M $file1 < -M $file2) {
    print "$file1 is newer than $file2.\n";
}

Upvotes: 1

Related Questions