Solved

find  unix command question

Posted on 2010-09-14
13
284 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 
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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

808 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