how to find file older than...

Erik Trulsson ertr1013 at
Tue Apr 8 12:41:09 PDT 2003

On Tue, Apr 08, 2003 at 03:11:04PM -0400, David Banning wrote:
> I want to delete files that are older than 1/2 hr in a particular
> directory. the only way I can think of doing it is by doing
> a "test" and comparing the date to another file. I would then
> have to create -that- comparison file 1/2 hour before.
> Is there an easier way?

Use find(1).  The version of find(1) included with FreeBSD has some
quite useful features that unfortunately are not available on all other
systems, but as long as you are not terribly concerned about portability
of your scripts you can use them.

For your particular problem the the following should work:

  find /path/to/directory ! -newerct '30 minutes ago' -print

Once you are satisfied that the above finds the files you want, you
might wish to change the '-print' into '-delete'

(Oh, and to create a file that has a creation time of 30 minutes ago
you can use the following:

touch -t `date -j -v -30M '+%Y%m%d%H%M'` /file/name


<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at

More information about the freebsd-questions mailing list