Saturday, December 8, 2007

Find files between two dates


To print all the files from 19-10-2007 to 21-11-2007

$ find . -type f -exec ls -l --time-style=full-iso {} \; | awk '{print $6,$NF}' | awk '{gsub(/-/,"",$1);print}' | awk '$1>= 20071019 && $1<= 20071121 {print $2}'

And to print all files from 2nd Nov 2007 to today, (Using -mtime with find command , and calculating the mtime based on the epoch times.)

$ FROM=`date --date='11/2/2007' +%s`
$ TO=`date +%s`

$ find /home/jsaikia/harness/rough/ -type f -mtime -`echo "(((($TO - $FROM ) / 24) / 60) / 60)" | bc` -print

If anyone got any better idea, please put in the comment section below.

4 comments:

Luis Garcia said...

I will script

find . -newermt "2011-04-01 16:00:00" ! -newermt "2011-08-01 23:00:00"

Unknown said...

@Luis, thanks, its useful.

Unknown said...

Hi in sh shell it showing unrecognized -newermt....please advise

Unknown said...

Hi Luis,

When i tried to use the -newermt in sh shell i m getting unrecognized newermt

please advise on what could be the issue

© Jadu Saikia www.UNIXCL.com