1825891 Members
3049 Online
109689 Solutions
New Discussion

help me

 
eric_88
Occasional Contributor

help me

hi expert,
I want to decide if the last modify time of file A is early 1 hour than file B,what can i do? how can i compare the time of two files?
hello
4 REPLIES 4
Peter Kloetgen
Esteemed Contributor

Re: help me

Hi Eric,

you need two commands to find out...

man find

--> have a look to the -newer option, remember that you can use a reference file to compare times.

man touch

--> you can use the touch- command to create a file with a time stamp which you need

This should do it for you.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
KapilRaj
Honored Contributor

Re: help me

ls -l filename|awk '{print $8}' gets the time.
compare them. i could not get any other leads

kaps
Nothing is impossible
Robin Wakefield
Honored Contributor

Re: help me

Hi Eric,

You could use perl to get the difference in the two dates:

diff=`perl -e '{print ((stat($ARGV[0]))[9]-(stat($ARGV[1]))[9]);}' fileA fileB`

diff will now contain the number of seconds between the mod times of the 2 files.

Rgds, Robin.
H.Merijn Brand (procura
Honored Contributor

Re: help me

diff=`perl -e '{print ((stat($ARGV[0]))[9]-(stat($ARGV[1]))[9]);}' fileA fileB`
is the diff in seconds. (one hour is 3600 seconds)

Hmmm,

diff=`perl -le 'print+(-M shift)-(-M shift)' fileA fileB`
prints the diff in days (hours and seconds as fraction of days)

1 hour = 0.0416667 day

Playing dirty:

perl -le '$^T=(stat shift)[9];-M shift()>-.0417 and print "Too old"' fileA fileB
Enjoy, Have FUN! H.Merijn