The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find files older than 2 hours pt14 AIX 3 03-05-2008 09:31 AM
Deleting Files Older than 24 hours mazhar803 SUN Solaris 7 09-27-2007 04:30 AM
removing files after 6 hours or older gthokala Shell Programming and Scripting 3 08-22-2005 07:59 PM
Finding only those files older than 2 hours mh53j_fe UNIX for Dummies Questions & Answers 2 07-01-2005 06:33 AM
Finding files older than 2 hours ianf Shell Programming and Scripting 1 05-27-2002 07:51 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-14-2005
Registered User
 

Join Date: Aug 2005
Posts: 1
unix command/s to find files older than 2 hours in a directory

I need to write a script to find files older than 2 hours in set of direcotries and list them ina mail. I know find command ti list files greater/lesser than days but i need to do it for hours. Any input.
Reply With Quote
Forum Sponsor
  #2  
Old 08-15-2005
Registered User
 

Join Date: Jul 2005
Location: England
Posts: 183
You need to use GNU find or some other find that supports some extra options... with GNU find the -amin, -cmin and -mmin deal in minutes rather than days.
Reply With Quote
  #3  
Old 08-15-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
try using touch to set a filetime on a dummy file, then use the ! -newer option
Code:
touch -t [[CC]YY]MMDDhhmm[.SS] somefile 
find . ! -newer somefile -print
Reply With Quote
  #4  
Old 08-17-2005
Registered User
 

Join Date: Aug 2003
Location: Ireland
Posts: 269
GNU find is brilliant - I would go with this..
Reply With Quote
  #5  
Old 08-17-2005
Registered User
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
This issue seems to pop a lot lately. Another solution is using awk:

ls -l | awk '{if($8 > 2) print $9}' | xargs rm

or something like that does the trick as well. You can combine filters like:

if($6 == Jul && $7 == 11 && $8 > 2)

to find all files of july 11, created or modified after 2 o'clock.
Reply With Quote
  #6  
Old 11-20-2007
Registered User
 

Join Date: Nov 2006
Posts: 1
find $DM_CTL_DIR -type f -mmin +120

will delete all files older than 2 hrs..
Reply With Quote
  #7  
Old 11-20-2007
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
Similar to the clauses "-atime", "-ctime" and "-mtime" there are "-amin", "-cmin" and "-mmin" which take minutes instead of days as operands. At least the find in AIX works that way. Here is an excerpt from "man find" (AIX 5.3):

Code:
       -amin Number
            Evaluates to the value True if the file has been accessed in
            Number-1 to Number minutes. For example, -amin 2 is true if the
            file has been accessed within 1 to 2 minutes.
       -cmin Number
            Evaluates to the value True if the file i-node (status
            information) has been changed in the specified number of minutes.
       -mmin Number
            Evaluates to the value True if the file has been modified in
            Number-1 to Number minutes
bakunin
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0