-1

How to find files on a server, which came on specific time period say 1 Jan to 31 March using grep, without scripts? Thanks!

Sahil
  • 13
  • 3
  • possible duplicate of [How to use 'find' to search for files created on a specific date?](http://stackoverflow.com/questions/158044/how-to-use-find-to-search-for-files-created-on-a-specific-date) – MaxChinni Jul 03 '15 at 09:10

1 Answers1

0

Can I answer with a command without grep?

find /path -type f -daystart \
  -mtime -$(( ($(date +%s) - $(date +%s -d '2015-01-01 -1 day')) /60/60/24 )) \
  -mtime +$(( ($(date +%s) - $(date +%s -d '2015-03-31 23:59:59')) /60/60/24 ))

This will find any file in the /path directory whose modification time is between 2015-01-01 00:00:00 and 2015-03-31 23:59:59 expressed as days ago.

I.e. today is 2015-06-29, so the command line will be expanded as

find /path -type f -daystart -mtime -180 -mtime +89
MaxChinni
  • 1,206
  • 14
  • 21