Search files between a date range

Hi people

A newbie here, thrown into the deep end. I want to select the group of files with in a range of dates and perform some operation on it. Are there inbuild date libraries i can use?

I did read thru the old posts on this topic. Couldnt get much idea :(, basically want to know how I can increment the dates or how unix does that, date formats (ddmmyy, dd MM yyyy, etc.), etc. I reckon the solution would be to find the right switched with 'find'. Pl help.

Thanx

you can use touch and find implement it.

You can use find command in this.
just do a
man find
and go through that,it will solve ur problem.

Thanks
Namish

yup thanx. i figured that out. im using somehting like this -

touch -d "$1" ./tmp1
touch -d "$2" ./tmp2
find -name '*.cdr' -newer ./tmp1 ! -newer ./tmp3

  1. I'm required to have the start/end dates in the format ddmmyyyy but touch seems to take only dd MMM or dd MMM yyyy. Can change/set the date format??

  2. '-newer' retreives the file created *after* creation date on tmp1. I want to search for the files created on or after creation of tmp1. how would I do that?

Thanx ppl.

1.touch only can accept its own time format, so you may adjust you to fit it. use -t parameter can adjust to minute(or second, it determind by your OS)
2.in fact, '-newer' retreives the file on or after, you can try it on your machine.

btw: what's ppl?

ppl means people. :slight_smile: Here is how I did a limited date range file search

The snippet below finds files modified between 2500 and 2800 minutes ago.

find -cmin +2500  -cmin -2800

The snippet below finds files modified between 20 and 21 days ago.

find -ctime +20  -ctime -21

I, too, am a hopeless newbie, but those worked for me.

Tom

#!/bin/ksh
#################################################
## File: findDateRange.sh
## Date: May 27, 2008
## Author: Saurav Sen
## Purpose: A script to find the files within
## a given date range
#################################################
echo "You have to provide the path, start date and the end date"
echo
echo "Enter the path to start search"
read fpath
echo "Please enter the start date in the format YYYYMMDD"
read strtdt
echo "please enter the end date in the format YYYYMMDD"
read enddt
touch -t ${strtdt}0000 /tmp/newerstart
touch -t ${enddt}2359 /tmp/newerend
#find ./ \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -print
find $fpath \( -newer /tmp/newerstart -a \! -newer /tmp/newerend \) -exec ls -l {} \;

count the no of days from now onwards

find dir/ -type f -mtime +7 -mtime -14 -print 2>/dev/null

this should give you the files for last week...you can tweak on the no of days.

-Devaraj Takhellambam