Date: Wed, 27 Dec 2006 18:53:17 +0300 From: Odhiambo Washington <wash@wananchi.com> To: freebsd-questions@freebsd.org Subject: Calculate the time of last modification of a file Message-ID: <20061227155317.GC95520@ns2.wananchi.com>
next in thread | raw e-mail | index | archive | help
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 } Here is the whole bash script, just so that everything is clear: <cut> #!/usr/local/bin/bash test -t 0 && trap "echo" EXIT NAME="$1"; shift DELAY="${1:-600}"; shift BASE="${1:-/var/run/greydata}"; shift NAME=${NAME//.//} DIR=$BASE/${NAME%/*} FILE=$DIR/${NAME##*/} test -d "$DIR" || mkdir -p "$DIR" test -f "$FILE" || { > "$FILE" echo -n yes exit 0 } # 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 } read <"$FILE" echo -n no exit 0 </cut> The `stat -c` is illegal for FreeBSD. However I don't seem to understand clearly what the man page for stat is telling me, to enable me make this work. -Wash http://www.netmeister.org/news/learn2quote.html DISCLAIMER: See http://www.wananchi.com/bms/terms.php -- +======================================================================+ |\ _,,,---,,_ | Odhiambo Washington <wash@wananchi.com> Zzz /,`.-'`' -. ;-;;,_ | Wananchi Online Ltd. www.wananchi.com |,4- ) )-,_. ,\ ( `'-'| Tel: +254 20 313985-9 +254 20 313922 '---''(_/--' `-'\_) | GSM: +254 722 743223 +254 733 744121 +======================================================================+ What is mind? No matter. What is matter? Never mind. -- Thomas Hewitt Key, 1799-1875
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061227155317.GC95520>