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.
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.
try using touch to set a filetime on a dummy file, then use the ! -newer option
touch -t [[CC]YY]MMDDhhmm[.SS] somefile
find . ! -newer somefile -print
GNU find is brilliant - I would go with this..
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.
find $DM_CTL_DIR -type f -mmin +120
will delete all files older than 2 hrs..
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):
-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