Find files modified in an interval on unix

findoptionsunix

I am on linux and have tried to figure out the find command for a while to be able to list the directories modified in a 24 hour period a certain number of days ago, but I can't get it to work. Among other things I have tried:

find -type d -mtime +1 -mtime -2

But it returns 0 matches, while find -type d -mtime +1 gives 16721 matches and find -type d -mtime -2 gives 120 matches. I should get around 50-60 matches.

I have also tried the -a option for AND in between but it makes no difference.

Best Answer

The arguments for the -mtime option to find are a little counter-intuitive. Basically, what you're asking for there is "show me everything that's older than two days ago, and younger than two days ago"... the '+' option is a little wonky (from find(1)):

When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.

For a single day range, you can just use -mtime 2, otherwise I suggest going to using -mmin and a bit of shell arithmetic to get where you want to go.