Find files
The Linux Cookbook: Tips and Techniques for Everyday Use: Finding Files
8.2.3 Finding Files in a Directory Tree by Modification Time
To find files last modified during a specified time, use find with the `-mtime' or `-mmin' options; the argument you give with `-mtime' specifies the number of 24-hour periods, and with `-mmin' it specifies the number of minutes.
* To list the files in the `/usr/local' directory tree that were modified exactly 24 hours ago, type:
$ find /usr/local -mtime 1 RET
* To list the files in the `/usr' directory tree that were modified exactly five minutes ago, type:
$ find /usr -mmin 5 RET
To specify a range of time, precede the number you give with either a plus sign (` ') to match times that are equal to or greater than the given argument, or a hyphen or minus sign (`-') to match times that are equal to or less than the given argument.
* To list the files in the `/usr/local' directory tree that were modified within the past 24 hours, type:
$ find /usr/local -mtime -1 RET
* To list the files in the `/usr' directory tree that were modified within the past five minutes, type:
$ find /usr -mmin -5 RET
Include the `-daystart' option to measure time from the beginning of the current day instead of 24 hours ago.
* To list all of the files in your home directory tree that were modified yesterday, type:
$ find ~ -mtime 1 -daystart RET
* To list all of the files in the `/usr' directory tree that were modified one year or longer ago, type:
$ find /usr -mtime 356 -daystart RET
* To list all of the files in your home directory tree that were modified from two to four days ago, type:
$ find ~ -mtime 2 -mtime -4 -daystart RET
In the preceding example, the combined options `-mtime 2' and `-mtime -4' matched files that were modified between two and four days ago.
To find files newer than a given file, give the name of that file as an argument to the `-newer' option.
* To find files in the `/etc' directory tree that are newer than the file `/etc/motd', type:
$ find /etc -newer /etc/motd RET
To find files newer than a given date, use the trick described in the find Info documentation: create a temporary file in `/tmp' with touch whose timestamp is set to the date you want to search for, and then specify that temporary file as the argument to `-newer'.
* To list all files in your home directory tree that were modified after May 4 of the current year, type:
$ touch -t 05040000 /tmp/timestamp RET
$ find ~ -newer /tmp/timestamp RET
In this example, a temporary file called `/tmp/timestamp' is written; after the search, you can remove it (see section Removing Files and Directories).
NOTE: You can also find files that were last accessed a number of days after they were modified by giving that number as an argument to the `-used' option. This is useful for finding files that get little use--files matching `-used 100', say, were accessed 100 or more days after they were last modified.