find unix command question


find . -mtime -1 -print will printfiles modified in the past 1 day...

how do i find files modified in past x hrs? say 2 hrs?

VlearnsAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
use File::Find;
$\=$/;
find(sub{(-M _) < 2/24 && print}, '/tmp/yautoprof/reports/imap_auth');
0
 
VlearnsAuthor Commented:
i am trying to use this in a  perl script
0
 
woolmilkporcConnect With a Mentor Commented:
Use -mmin (min = minutes) instead of mtime.


0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
VlearnsAuthor Commented:
find  /tmp/yautoprof/reports/imap_auth  -mtime -1h   thi works too
0
 
_-MYFOX-_Commented:
find . -type f -mmin -120
0
 
woolmilkporcCommented:
>> -mtime -1h   this works too <<

Are you sure? It doesn't work for me. the "h" is silently ignored.
0
 
TintinCommented:
Note that mmin is a GNU extension to find, so depending on what *nix flavour you are using, it make not have it, in which case use ozo's Perl solution.
0
 
ozoCommented:
you could also touch a file and use -newer
but since you are trying to use this in a  perl script, you might as well use perl functions
0
 
ChendurDasanConnect With a Mentor Commented:
Please try this for a recursive search. You can also use glob and restrict to currend dir

use File::Find;
use File::Copy;

my $now = time;

sub search {
$stamp = (stat($_))[9];
if  (( $now - $stamp ) < ( 24 * 60 * 60 )) {
print "Copying ". $_ . "\n" ;
copy ($_ , "" );
}
}

find (\&search , "." );
0
 
ChendurDasanCommented:
Please try this for a recursive search. You can also use glob and restrict to currend dir

use File::Find;
use File::Copy;

my $now = time;

sub search {
$stamp = (stat($_))[9];
if  (( $now - $stamp ) < ( 24 * 60 * 60 )) {
print "Copying ". $_ . "\n" ;
copy ($_ , "" );
}
}

find (\&search , "." );
0
 
VlearnsAuthor Commented:
you could also touch a file and use -newer
but since you are trying to use this in a  perl script, you might as well use perl functions

not sure how to implement this one...any ideas...thanks!
0
 
ozoCommented:
http:#a33678171 and http:#a33682553 implement this
0
 
VlearnsAuthor Commented:
thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.