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?
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.
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]