Solved

find  unix command question

Posted on 2010-09-14
13
275 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?

0
Comment
Question by:Vlearns
  • 4
  • 3
  • 2
  • +3
13 Comments
 

Author Comment

by:Vlearns
ID: 33677810
i am trying to use this in a  perl script
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 166 total points
ID: 33677843
Use -mmin (min = minutes) instead of mtime.


0
 

Author Comment

by:Vlearns
ID: 33677858
find  /tmp/yautoprof/reports/imap_auth  -mtime -1h   thi works too
0
 
LVL 5

Expert Comment

by:_-MYFOX-_
ID: 33677860
find . -type f -mmin -120
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33677875
>> -mtime -1h   this works too <<

Are you sure? It doesn't work for me. the "h" is silently ignored.
0
 
LVL 84

Accepted Solution

by:
ozo earned 167 total points
ID: 33678171
use File::Find;
$\=$/;
find(sub{(-M _) < 2/24 && print}, '/tmp/yautoprof/reports/imap_auth');
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 48

Expert Comment

by:Tintin
ID: 33678643
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
 
LVL 84

Expert Comment

by:ozo
ID: 33678667
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
 

Assisted Solution

by:ChendurDasan
ChendurDasan earned 167 total points
ID: 33682553
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
 

Expert Comment

by:ChendurDasan
ID: 33682561
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
 

Author Comment

by:Vlearns
ID: 33720282
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
 
LVL 84

Expert Comment

by:ozo
ID: 33723319
http:#a33678171 and http:#a33682553 implement this
0
 

Author Closing Comment

by:Vlearns
ID: 33774718
thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now