1

I know of this command find . -type f -newermt 2010-10-07 ! -newermt 2014-10-08, which can find the files modified between two dates. But here, the problem is to find files that were
modified between 2 and 5 days. So giving dates is not an option. Is there some option of the find command which can do this, or some alternative?

1
  • Did you try playing with -mtime -5 and -mtime +2 ?
    – MC68020
    Jan 19, 2022 at 18:22

1 Answer 1

3

From man find:

-mtime n

File's data was last modified less than, more than or exactly n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification time.

-atime n

File was last accessed less than, more than or exactly n*24 hours ago. 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.

find . -mtime +1 -mtime -5

Pay close attention on what value of n to chose - it is not that intuitively on first sight.

+1 means more than 1*24h, but as the fraction is ignored, it includes 1.9*24h and the accepted time range starts with exactly 2*24h (interval [1,2)). So the upper border is of interest.

In the case of -5 it means less than exactly 5*24h, with the interval for 5 as [5,6) or 5<=x<6 in other notation. So there the lower border is of interest.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .