Re: Testing file age in seconds
From: Netocrat (netocrat_at_dodo.com.au)
Date: 06/13/05
- Previous message: John Cordes: "Re: Variable LINES in bash script"
- In reply to: Netocrat: "Testing file age in seconds"
- Next in thread: John L: "Re: Testing file age in seconds"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 13 Jun 2005 10:37:42 GMT
Netocrat wrote:
> I'd like to test whether a file is older than a specified age in seconds
> from within a bash shell script. It would be acceptable to use another
> utility such as find or awk but I wouldn't want to rely on something such
> as perl or python being present.
I've found the stat command which doesn't seem to be standard and portable
but is better than a self-made executable. My code is:
FILETIME=`stat -c %Y $PATHTOFILE`
NOW=`date +%s`
if [ $NOW-$FILETIME -gt $AGE ]
then
# File is older
else
# File is not older
fi
Let me know of anything more portable.
- Previous message: John Cordes: "Re: Variable LINES in bash script"
- In reply to: Netocrat: "Testing file age in seconds"
- Next in thread: John L: "Re: Testing file age in seconds"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|