![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#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.
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
GNU find is brilliant - I would go with this..
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
find $DM_CTL_DIR -type f -mmin +120
will delete all files older than 2 hrs.. |
|
#7
|
|||
|
|||
|
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
|
|||
| Google The UNIX and Linux Forums |