how to test if a file is more than one hour old in ksh

how to test if a file is more than one hour old in ksh

am 19.04.2008 04:40:26 von SamL

I am looking for a simple way to test if a file is more than one hour
old in ksh. I think 'find' command may be able to do that but I do not
know the detail. Any help? Thanks.

Re: how to test if a file is more than one hour old in ksh

am 19.04.2008 04:52:36 von Ed Morton

On 4/18/2008 9:40 PM, SamL wrote:
> I am looking for a simple way to test if a file is more than one hour
> old in ksh. I think 'find' command may be able to do that but I do not
> know the detail. Any help? Thanks.
>

If by "old" you mean how long has it been since it was created, you can't
(unless you save the information yourself) as UNIX doesn't store file creation
time. If you mean how long since it was last modified, what you probably are
looking for is:

find . -maxdepth 1 -ctime +1 -name file

Regards,

Ed

Re: how to test if a file is more than one hour old in ksh

am 19.04.2008 11:49:00 von Joachim Schmitz

Ed Morton wrote:
> On 4/18/2008 9:40 PM, SamL wrote:
>> I am looking for a simple way to test if a file is more than one hour
>> old in ksh. I think 'find' command may be able to do that but I do
>> not know the detail. Any help? Thanks.
>>
>
> If by "old" you mean how long has it been since it was created, you
> can't (unless you save the information yourself) as UNIX doesn't
> store file creation time. If you mean how long since it was last
> modified, what you probably are looking for is:
>
> find . -maxdepth 1 -ctime +1 -name file
But that's days, not hours.

Bye, Jojo

Re: how to test if a file is more than one hour old in ksh

am 19.04.2008 12:18:20 von Dave B

On Saturday 19 April 2008 11:49, Joachim Schmitz wrote:

>> If by "old" you mean how long has it been since it was created, you
>> can't (unless you save the information yourself) as UNIX doesn't
>> store file creation time. If you mean how long since it was last
>> modified, what you probably are looking for is:
>>
>> find . -maxdepth 1 -ctime +1 -name file
> But that's days, not hours.

Then I guess we need some math:

if [ $(( $(date +%s) - $(stat -c %Z file) )) -gt 3600 ]; then
....
fi

(or %Y instead of %Z if we want the modification time)

Or, with GNU find (adapted from Ed's):

find . -maxdepth 1 -cmin +60 -name file

(or -mmin if we want the modification time), and test if the command outputs
something.

All the above solutions need GNU tools. Not sure whether standard methods
exist for doing the same thing.

--
D.

Re: how to test if a file is more than one hour old in ksh

am 19.04.2008 20:25:05 von Dan Mercer

"Ed Morton" wrote in message
news:48095E74.1040509@lsupcaemnt.com...
> On 4/18/2008 9:40 PM, SamL wrote:
>> I am looking for a simple way to test if a file is more than one hour
>> old in ksh. I think 'find' command may be able to do that but I do not
>> know the detail. Any help? Thanks.
>>
>
> If by "old" you mean how long has it been since it was created, you can't
> (unless you save the information yourself) as UNIX doesn't store file
> creation
> time. If you mean how long since it was last modified, what you probably
> are
> looking for is:
>
> find . -maxdepth 1 -ctime +1 -name file

You demonstrate a common misconception about find - that the format is

find dir -switches ...

the true format is

find files ... -switches

You can have multiple files and the files can be of any type - remember, a
directory
is just a particular type of file

However, the the time values in find are days not hours.
You could always use touch to touch a file with a back date - that's kind of
kludgy.

touch -t CCYYMMDDhhmm /tmp/touchstone
if [[ $file -ot /tmp/touchstone ]]

You could use perl

if perl -e 'exit(!(-M "/path/to/file") > 1.0'
then
echo older
else
echo not older
fi



>
> Regards,
>
> Ed
>

Re: how to test if a file is more than one hour old in ksh

am 19.04.2008 23:40:38 von mop2

For a given file:

[ $(($(date +%s)-$(date -r file +%s))) -ge 3600 ]&&echo old



SamL wrote:
> I am looking for a simple way to test if a file is more than one hour
> old in ksh. I think 'find' command may be able to do that but I do not
> know the detail. Any help? Thanks.

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 01:01:18 von Dave Kelly

On Apr 19, 4:40 pm, mop2
wrote:
> For a given file:
>
> [ $(($(date +%s)-$(date -r file +%s))) -ge 3600 ]&&echo old
>
> SamL wrote:
> > I am looking for a simple way to test if a file is more than one hour
> > old in ksh. I think 'find' command may be able to do that but I do not
> > know the detail. Any help? Thanks.

Depending where the files exist. My manual says 'lynx' will open
local files.
See if information in this script snippet will help.

LDPTIME=$(date -d "`lynx -dump http://www.tldp.org/timestamp.txt`" +
%s)
TIMESTAMP=$(date -d "`lynx -error_file=lynx_error -dump -
connect_timeout=20 $url/timestamp.txt`" +%s)

if [ "$TIMESTAMP" == "" ] ; then
continue
fi
TIMEFRAME=$(($LDPTIME - $TIMESTAMP))
printf "Time frame is %s minus %s equal %s\n" "$LDPTIME"
"$TIMESTAMP" "$TIMEFRAME"
if [ "$TIMEFRAME" -gt 1209600 ] ; then

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 04:46:25 von SamL

On Apr 19, 6:18 am, Dave B wrote:
> On Saturday 19 April 2008 11:49, Joachim Schmitz wrote:
>
> >> If by "old" you mean how long has it been since it was created, you
> >> can't (unless you save the information yourself) as UNIX doesn't
> >> store file creation time. If you mean how long since it was last
> >> modified, what you probably are looking for is:
>
> >> find . -maxdepth 1 -ctime +1 -name file
> > But that's days, not hours.
>
> Then I guess we need some math:
>
> if [ $(( $(date +%s) - $(stat -c %Z file) )) -gt 3600 ]; then
> ...
> fi
>
> (or %Y instead of %Z if we want the modification time)
>
> Or, with GNU find (adapted from Ed's):
>
> find . -maxdepth 1 -cmin +60 -name file
>
> (or -mmin if we want the modification time), and test if the command outputs
> something.
>
> All the above solutions need GNU tools. Not sure whether standard methods
> exist for doing the same thing.
>
> --
> D.

I am using AIX and unfortunately do not have the stat command, so I
tried the find command approach.

It essentially works. Only one thing, it will return 0 even if there
is no files found satisfying the criteria. So

find . -maxdepth 1 -cmin +60 -name file >/tmp.$$
[[ -s /tmp.$$ ]] && echo "old"

Thanks to all those who replied.

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 11:26:46 von Stephane CHAZELAS

2008-04-18, 19:40(-07), SamL:
> I am looking for a simple way to test if a file is more than one hour
> old in ksh. I think 'find' command may be able to do that but I do not
> know the detail. Any help? Thanks.


If you're implementation of ksh is zsh's, *(mh+1) expands to the
list of files that are more than 1 hour old.

--
Stéphane

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 12:21:42 von Dave B

On Saturday 19 April 2008 20:25, Dan Mercer wrote:

>> time. If you mean how long since it was last modified, what you probably
>> are looking for is:
>>
>> find . -maxdepth 1 -ctime +1 -name file
>
> You demonstrate a common misconception about find - that the format is
>
> find dir -switches ...
>
> the true format is
>
> find files ... -switches

Where did you read that? From the standard man page:

find [ -H | -L ] path ... [ operand_expression ... ]

--
D.

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 14:24:33 von Dave B

On Sunday 20 April 2008 12:21, Dave B wrote:

>> the true format is
>>
>> find files ... -switches
>
> Where did you read that? From the standard man page:
>
> find [ -H | -L ] path ... [ operand_expression ... ]

Ah ok, now I see what you mean. I never looked at "find" that way. Thanks!

--
D.

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 18:33:12 von Dan Mercer

"Dave B" wrote in message
news:fuf5f5$pes$1@registered.motzarella.org...
> On Saturday 19 April 2008 20:25, Dan Mercer wrote:
>
>>> time. If you mean how long since it was last modified, what you probably
>>> are looking for is:
>>>
>>> find . -maxdepth 1 -ctime +1 -name file
>>
>> You demonstrate a common misconception about find - that the format is
>>
>> find dir -switches ...
>>
>> the true format is
>>
>> find files ... -switches
>
> Where did you read that? From the standard man page:
>
> find [ -H | -L ] path ... [ operand_expression ... ]

find -H | -L are not standard find options - they may be Gnu find options,
but I've never seen them.
The synopsis for the standard find is

find path-name-list [expression]

Gnu find is a bit of a mess - if you're going to vary that far from the
original concept, maybe you
should reconsider renaming the program.

Dan Mercer

>
> --
> D.
>

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 18:40:34 von Dave B

On Sunday 20 April 2008 18:33, Dan Mercer wrote:

>> Where did you read that? From the standard man page:
>>
>> find [ -H | -L ] path ... [ operand_expression ... ]
>
> find -H | -L are not standard find options - they may be Gnu find options,
> but I've never seen them.
> The synopsis for the standard find is
>
> find path-name-list [expression]

Uhm, no. I copied/pasted that directly from the SUSv3 standard, so I suppose
that they *are* standard.

--
D.

Re: how to test if a file is more than one hour old in ksh

am 20.04.2008 19:24:49 von unknown

Post removed (X-No-Archive: yes)

Re: how to test if a file is more than one hour old in ksh

am 21.04.2008 17:28:43 von Chris Mattern

On 2008-04-20, SamL wrote:
> On Apr 19, 6:18 am, Dave B wrote:
>> On Saturday 19 April 2008 11:49, Joachim Schmitz wrote:
>>
>> >> If by "old" you mean how long has it been since it was created, you
>> >> can't (unless you save the information yourself) as UNIX doesn't
>> >> store file creation time. If you mean how long since it was last
>> >> modified, what you probably are looking for is:
>>
>> >> find . -maxdepth 1 -ctime +1 -name file
>> > But that's days, not hours.
>>
>> Then I guess we need some math:
>>
>> if [ $(( $(date +%s) - $(stat -c %Z file) )) -gt 3600 ]; then
>> ...
>> fi
>>
>> (or %Y instead of %Z if we want the modification time)
>>
>> Or, with GNU find (adapted from Ed's):
>>
>> find . -maxdepth 1 -cmin +60 -name file
>>
>> (or -mmin if we want the modification time), and test if the command outputs
>> something.
>>
>> All the above solutions need GNU tools. Not sure whether standard methods
>> exist for doing the same thing.
>>
>> --
>> D.
>
> I am using AIX and unfortunately do not have the stat command, so I
> tried the find command approach.
>
> It essentially works. Only one thing, it will return 0 even if there
> is no files found satisfying the criteria. So
>
> find . -maxdepth 1 -cmin +60 -name file >/tmp.$$
> [[ -s /tmp.$$ ]] && echo "old"
>
Look, Ma, no temp files!

[[ "$(find . -maxdepth 1 -cmin +60 -name file)" = "" ]] && echo "old"

--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Re: how to test if a file is more than one hour old in ksh

am 21.04.2008 17:37:02 von gazelle

In article ,
Chris Mattern wrote:
....
>Look, Ma, no temp files!
>
>[[ "$(find . -maxdepth 1 -cmin +60 -name file)" = "" ]] && echo "old"

Let's count the minutes until one of the standards jockeys comes along
and tells you that that requies GNU tools...

Re: how to test if a file is more than one hour old in ksh

am 21.04.2008 17:41:19 von Stephane CHAZELAS

2008-04-21, 15:37(+00), Kenny McCormack:
> In article ,
> Chris Mattern wrote:
> ...
>>Look, Ma, no temp files!
>>
>>[[ "$(find . -maxdepth 1 -cmin +60 -name file)" = "" ]] && echo "old"
>
> Let's count the minutes until one of the standards jockeys comes along
> and tells you that that requies GNU tools...

That requires GNU or FreeBSD tools.

And as you pointed out, it should have been

find file -prune -cmin +60 -print | grep -q .

Or you could have used

find file -chour +1 -exit 0 -o -exit 1

If you have the proper implementation/version of find.

--
Stéphane