Sunday, July 14, 2013

how to find files with specific date range

There seems to be no direct option in find command to specify the date and get the files with specified modified date, but find command provide -newer option which will find files newer than file specified. so, here is small tweak which worked for me.

Variable:
Sdate=07/02/2013
Stime=19:00:00
Edate=07/05/2013
Etime=18:00:00
WRKDIR=/data/log
TEMPDIR= /home/dba/temp

1. create a file with modified date as start date.

> touch -d "$Sdate $Stime" $TEMPDIR/start

2. create a file with modified date as end date

> touch -d "$Edate $Etime" $TEMPDIR/end

3. find command

> find $JIRDIR -newer $TEMPDIR/start -and -not -newer  $TEMPDIR/end >$TEMPDIR/tmp_jir.txt

"tmp_jir.txt" file contains file names between the specified date range.


No comments:

Post a Comment