Solved

find  unix command question

Posted on 2010-09-14
13
283 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.
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.

831 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