find files 2 hours old

From: Bill Thompson (bill.thompson@GOODYEAR.COM)
Date: Tue Jun 17 2003 - 07:31:54 EDT


John,

Here's a script that will list all of the files on the system that are more
than twelve hours old. The key is the computing a date 12 hours in the
past. This is done with the following line:

TWELVE_HOURS_AGO=$(TZ=EST17EDT16;date '+%Y%m%d%H%M')

Note that TZ in my part of the world is "EST5EDT4". To compute the time 12
hours ago, I just added 12 to both numbers to come up with "EST17EDT16".
You'll have to make adjustments for your local timezone.

Also, the subject line of your post said two hours but the body said
twelve. No matter - If you really want to find files that are older than
two hours (rather than twelve) just adjust the TZ variable appropriately.

- - - - - snip - - - - -
#!/usr/bin/sh

    # compute the time twelve hours ago in the form of "CCYYMMDDhhmm"
    TWELVE_HOURS_AGO=$(TZ=EST17EDT16;date '+%Y%m%d%H%M')

    # create the name for the temporary file
    TOUCH_FILE="/tmp/${TWELVE_HOURS_AGO}.$$"

    # get rid of the temp file if the script is aborted
    trap "rm -f $TOUCH_FILE" 1 2 3 15

    # create the temp file with a time stamp of twelve hours ago
    touch -a -m -t $TWELVE_HOURS_AGO $TOUCH_FILE

    # find all the files older than the temp file
    find / ! -newer $TOUCH_FILE -ls

    # get rid of the temp file
    rm -f $TOUCH_FILE
- - - - - snip - - - - -

Bill Thompson
Sr UNIX Systems Administrator
The Goodyear Tire & Rubber Co.

Contains Confidential and/or Proprietary Information
May Not Be Copied or Disseminated Without Express Consent of The Goodyear
Tire & Rubber Company.

AIX-L Archives: http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2

----- Original Message -----
From: "John Dunn" <john.dunn@SEFAS.CO.UK>
Newsgroups: bit.listserv.aix-l
To: <aix-l@Princeton.EDU>
Sent: Tuesday, June 17, 2003 3:58 AM
Subject: find files 2 hours old

> Is there anyway to get find to identify files that have not been modified
> for 12 hours?
>
> John



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:55 EDT