We help IT Professionals succeed at work.

find  unix command question

Vlearns
Vlearns asked
on
307 Views
Last Modified: 2012-05-10

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?

Comment
Watch Question

Author

Commented:
i am trying to use this in a  perl script
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
find  /tmp/yautoprof/reports/imap_auth  -mtime -1h   thi works too
find . -type f -mmin -120
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
>> -mtime -1h   this works too <<

Are you sure? It doesn't work for me. the "h" is silently ignored.
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2007

Commented:
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.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

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
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
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 , "." );

Author

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!
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
http:#a33678171 and http:#a33682553 implement this

Author

Commented:
thanks!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.