Find All Files Created in Specified Time Interval

This is totally dumb, but I just can’t figure out how to do this “in place”. I want to find all the files of a given type in a certain directory, and it’s subdirectories that were created in a given time interval. So for example, find all the jpg images that were created in 2006.

I can do it in 3 steps (4 if you count cleanup of temp files):

touch --date="01/01/2006" /tmp/t.06$$
touch --date="01/01/2007" /tmp/t.07$$
find ~/scans -newer /tmp/t.06$$ ! -newer /tmp/t.07$$ -iname "*.jpg"
rm -f /tmp/t.0*$$

It works, but it seems to be way to much work for something this silly. There really should be a way to do this in one step. What am I missing here?

Update 02/23/2007 12:55:23 PM

I created a bash script of this for convenience. It takes in 4 parameters: the path to be searched, the start date, the end date, and file type.

#!/bin/bash
touch --date="$2" /tmp/t.01$$
touch --date="$3" /tmp/t.02$$
find $1 -newer /tmp/t.01$$ ! -newer /tmp/t.02$$ -iname "*.$4"
rm -f /tmp/t.0?$$

Sample usage would be:

findfrom ~/scans 01/01/2006 01/01/2007 jpg

That’s of cours assuming that you call this script findfrom like I did.

[tags]files, file dates, unix, find, linux, touch, bash[/tags]

This entry was posted in Uncategorized. Bookmark the permalink.



2 Responses to Find All Files Created in Specified Time Interval

  1. Craig Betts UNITED STATES Mozilla Firefox Mac OS Terminalist says:

    That is exactly how I would do it, except it would be on one command line with each of your lines seperated by a semicolon. If you want simplicity, write a script that creates and removes the files for you.

    Reply  |  Quote
  2. Luke UNITED STATES Mozilla Firefox Ubuntu Linux says:

    Ok, so it’s not me. It’s just find being awkward and silly with it’s non-standard syntax.

    For a moment there I thought maybe I’m just being dense here. :P

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *