Operating System - HP-UX
1753440 Members
4655 Online
108794 Solutions
New Discussion юеВ

Re: Files 15 mins older than sysdate

 
SOLVED
Go to solution
Yvonne Butler
Regular Advisor

Files 15 mins older than sysdate

Hi

Does anyone know how I can get find to give me a list of files within a directory that is 15 minutes or more older that the current system date? Or does anyone have a handy little script that does this? More than this I need really a count of how many files are within a directory that are 15 minutes or more older than the system date.

Thanks
13 REPLIES 13
Mel Burslan
Honored Contributor

Re: Files 15 mins older than sysdate

touch -t MMDDhhmm /tmp/dummyfile # where hhmm is timestamp of 15 minutes ago

cd /my/directory
find ./ -newer /tmp/dummyfile | wc -l


hope this helps
________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi Yvonne:

You can use:

# perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -M _ <= (15/(60*60*24))},$path)' /dirname

If you omit the "/dirname" argument, your current working directory will be examined.

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Files 15 mins older than sysdate

Here's a pseudo-script, you'll need to do the translation:

get current time using date
manipulate that time by subtracting 15 minutes
use find with -older to find files matching
pipe results to "wc -l"


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi (again):

Oops, you want files _OLDER_ so:

# perl -MFile::Find -le '$path=shift||qq(.);find(sub{print $File::Find::name if -f $_ && -M _ >= (15/(60*60*24))},$path)' /directory

Regards!

...JRF...
Yvonne Butler
Regular Advisor

Re: Files 15 mins older than sysdate

The perl command doesn't seem to work:

Can't locate File/Find.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1 /opt/perl5/lib/5.00502 /opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .).
BEGIN failed--compilation aborted.

Patrick Wallek
Honored Contributor

Re: Files 15 mins older than sysdate

Mel's find command will work with 1 changes, since you want files OLDER than sysdate - 15 minutes.

find ./ ! -newer /tmp/dummyfile

Notice the '!' prior to the '-newer' to make it not newer than the /tmp/dummyfile.
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi Yvonne:

Perl 5.005 is OLD. If you want, update to a current (5.8.8 or later) version:

http://h20392.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Files 15 mins older than sysdate

Hi (one more time):

I'm sorry, NO POINTS FOR THIS CORRECTION, but for 15 _minutes_ use:

(15/(60*24))

NOT:

(15/(60*60*24))

...which represents 15 _seconds_

Regards!

...JRF...
Yvonne Butler
Regular Advisor

Re: Files 15 mins older than sysdate

I'm trying to upgrade the Perl installed on this system but now I've hit another issue, for some reason the system isn't allowing me to swinstall anything, I get a message about not having permission for this operation when I'm root!

Anyway, once I've got this fixed and have installed the later version of Perl, I'll try again.