UNIX find with dates

-atime/-ctime/-mtime the last time a files's access time, file status and modification time, measured in days or minutes. Time interval in options -ctime, -mtime and -atime is an integer with optional sign.

  • n: If the integer n does not have sign this means exactly n days ago, 0 means today.
  • +n: if it has plus sing, then it means more then n days ago, or older then n,
  • -n: if it has the minus sign, then it means less than n days ago (-n), or younger then n. It's evident that -1 and 0 are the same and both mean today.

Examples:

  • Find everything in your home directory modified in the last 24 hours: $ find $HOME -mtime 0

  • Find everything in your home directory modified in the last 7 days: $ find $HOME -mtime -7

  • Find everything in your home directory that have NOT been modified in the last year: $ find $HOME -mtime +365

  • To find html files that have been modified in the last seven days, I can use -mtime with the argument -7 (include the hyphen): $ find . -mtime -7 -name "*.html" -print

If you use the number 7 (without a hyphen), find will match only html files that were modified exactly seven days ago:

 `$ find . -mtime 7 -name "*.html" -print`
  • To find those html files that I haven't touched for at least 7 days, I use +7:

    $ find . -mtime +7 -name "*.html" -print