AZ.dev

Find files modified within a certain time range

| posix: any gnu-findutils: any

To find files by age, use find’s -mtime flag. The sign works backwards from what feels natural.

The Fix

find . -mtime -1   # modified less than 1 day ago
find . -mtime +7   # modified more than 7 days ago
find . -mtime 3    # modified exactly 3 days ago (rarely what you want)

For finer granularity, -mmin does the same thing in minutes:

find . -mmin -60   # modified in the last hour

Why the Sign Feels Backwards

-n means “less than n”, +n means “more than n”. Read -1 as “younger than 1 day” and +7 as “older than 7 days”, not as a literal day count.

Gotchas

find mtime shell files unix

Was this helpful?

Related Entries

Get the full (absolute) path of a fileRun a command on every file find matches