Find files within a specific date range.

I have to admit google was indeed my friend and I found a great article which did the business at http://my.galagzee.com/2009/02/23/unix-shell-find-files-by-a-date-range/

Essentially I needed to transfer some nmon files from a remote server to my Sun workstation for just one specific week, from 02/04/2010 to 09/04/2010. On the remote server I did;

touch -t 201004020000 range_start
touch -t 201004092359 range_end

Then using the following find command I was able to list all the files I needed and scp them over.

find /nmonstats -type f -newer range_start ! -newer range_end -ls

Nice.

As a side note, we can get yesterday’s date using:

date -d '1 day ago' +%Y%m%d

To find the last working day we can use:

DAY_OF_WEEK=`date +%w`
if [ $DAY_OF_WEEK == 1 ] ; then
  LOOK_BACK=3
else
  LOOK_BACK=1
fi
 
yesterday=`date -d "$LOOK_BACK day ago" +'%Y%m%d'`