Calculate the time of last modification of a file

N.J. Mann njm at njm.f2s.com
Wed Dec 27 08:50:18 PST 2006


On Wednesday, 27 December, 2006 at 18:53:17 +0300, Odhiambo Washington wrote:
> Hiya,
> 
> I hope you had a merry Christmas ;)
> 
> I am trying to determine the time of last modification of a file,
> on FreeBSD.
> 
> The following code achieves the same on Linux:
> 
> 
> # AGE = (current time) - (time of last modification of "$FILE")
> # please check your systems 'stat' command!
> AGE=$(($(date +%s) - $(stat -c '%Y' "$FILE")))
> 
> test $AGE -lt $DELAY && {
>         echo -n yes
>         exit 0
> }

I *think* what you are looking for is:

  stat -f '%Sm' -t '%s'

There is probably a much easier way to do that, but I couldn't find it
in the five minutes I had to spare.  :-)


Cheers,
       Nick.
-- 
Please do not CC me on replies, I read the list and don't need the dupes.



More information about the freebsd-questions mailing list