17
7
How do I compare the timestamp of two files?
I tried this but it doesn't work:
file1time=`stat -c %Y fil1.txt`
file2time=`stat -c %Y file2.txt`
if[$file1time -gt $file2time];
then
doSomething
fi
I printed both the time stamps, in order and it gives me
1273143480
1254144394
./script.sh: line 13: [1273143480: command not found
So basically if comparison is not working, I guess. Or if there is any other nice way than what I am doing, please let me know. What do I have to change?
1Your code needs spaces around the square brackets. – Jonathan Leffler – 2010-05-06T15:02:57.587
The test mechanism is very complex compared with the built in mechanism for comparing time stamps. – Jonathan Leffler – 2010-05-06T15:03:32.360