Calculate the time of last modification of a file

Dan Nelson dnelson at allantgroup.com
Wed Dec 27 08:54:45 PST 2006


In the last episode (Dec 27), Odhiambo Washington said:
> 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
> }

You can use "stat -f '%m' $FILE", which is identical to Linux's 
"stat -c '%Y' $FILE" .

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-questions mailing list