From: SamL on
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.

From: Ed Morton on
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

From: Joachim Schmitz on
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


From: Dave B on
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.
From: Dan Mercer on

"Ed Morton" <morton(a)lsupcaemnt.com> wrote in message
news:48095E74.1040509(a)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
>