Finding file by access modification time
suggest changeOn an ext filesystem, each file has a stored Access, Modification, and (Status) Change time associated with it - to view this information you can use stat myFile.txt; using flags within find, we can search for files that were modified within a certain time range.
To find files that have been modified within the last 2 hours:
$ find . -mmin -120
To find files that have not been modified within the last 2 hours:
$ find . -mmin +120
The above examples search only on the modified time. To search on access times or changed times, use a or c accordingly.
$ find . -amin -120
$ find . -cmin +120
General format:
-mmin n: file was modified n minutes ago-mmin -n: file was modified less than n minutes ago-mmin +n: file was modified more than n minutes ago
Find files that have been modified within the last 2 days:
find . -mtime -2
Find files that have not been modified within the last 2 days
find . -mtime +2
Use -atime and -ctime for access time and status change time respectively.
General format:
-mtime n: file was modified n×24 hours ago-mtime -n: file was modified less than n×24 hours ago-mtime +n: file was modified more than n×24 hours ago
Find files modified in a range of dates, from 2007-06-07 to 2007-06-08:
find . -type f -newermt 2007-06-07 ! -newermt 2007-06-08
Find files accessed in a range of timestamps (using files as timestamp), from 1 hour ago to 10 minutes ago:
touch -t $(date -d '1 HOUR AGO' +%Y%m%d%H%M.%S) start_date
touch -t $(date -d '10 MINUTE AGO' +%Y%m%d%H%M.%S) end_date
timeout 10 find "$LOCAL_FOLDER" -newerat "start_date" ! -newerat "end_date" -print
General format:
-newerXY reference : Compares the timestamp of the current file with reference. XY could have one of the following values: at (access time), mt (modification time), ct (change time) and more. reference is the name of a file whose timestamp we want to compare (access, modification, or change) or a string describing an absolute time. date -d in the example above is a GNU extension.