Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

/proc/kallsyms format, sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas

Links

XODOX
Impressum

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

Posted on 2008-04-19 04:40:26 by 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.

Report this message

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

Posted on 2008-04-19 04:52:36 by 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

Report this message

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

Posted on 2008-04-19 11:49:00 by 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

Report this message

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

Posted on 2008-04-19 12:18:20 by 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.

Report this message

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

Posted on 2008-04-19 20:25:05 by Dan Mercer

"Ed Morton" <morton@lsupcaemnt.com> 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
>

Report this message

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

Posted on 2008-04-19 23:40:38 by 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.

Report this message

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

Posted on 2008-04-20 01:01:18 by Dave Kelly

On Apr 19, 4:40 pm, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...@gmail.com>
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

Report this message

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

Posted on 2008-04-20 04:46:25 by SamL

On Apr 19, 6:18 am, Dave B <da...@addr.invalid> 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.

Report this message

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

Posted on 2008-04-20 11:26:46 by 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

Report this message

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

Posted on 2008-04-20 12:21:42 by 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.

Report this message

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

Posted on 2008-04-20 14:24:33 by 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.

Report this message

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

Posted on 2008-04-20 18:33:12 by Dan Mercer

"Dave B" <daveb@addr.invalid> 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.
>

Report this message

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

Posted on 2008-04-20 18:40:34 by 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.

Report this message

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

Posted on 2008-04-20 19:24:49 by unknown

Post removed (X-No-Archive: yes)

Report this message

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

Posted on 2008-04-21 17:28:43 by Chris Mattern

On 2008-04-20, SamL <slsamliu@gmail.com> wrote:
> On Apr 19, 6:18 am, Dave B <da...@addr.invalid> 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

Report this message

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

Posted on 2008-04-21 17:37:02 by gazelle

In article <slrng0pcl9.gg3.syscjm@sumire.gwu.edu>,
Chris Mattern <matternc@comcast.net> 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...

Report this message

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

Posted on 2008-04-21 17:41:19 by Stephane CHAZELAS

2008-04-21, 15:37(+00), Kenny McCormack:
> In article <slrng0pcl9.gg3.syscjm@sumire.gwu.edu>,
> Chris Mattern <matternc@comcast.net> 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

Report this message