Recursively find all files newer than a given time

Given time_t:

date -ur 1312603983 Sat 6 Aug 2011 04:13:03 UTC 

I'm looking for one

Something like

 find . --newer 1312603983 

But with time_t instead of file.

+42
linux bash
Aug 6 '11 at 4:22
source share
6 answers

This is a bit cool because touch does not accept the value raw time_t , but it should make the job pretty safe in the script. (The -r option for date present in MacOS X, I have not double-checked GNU.) Using the variable "time", we could replace command substitution directly on the touch command line.

 time=$(date -r 1312603983 '+%Y%m%d%H%M.%S') marker=/tmp/marker.$$ trap "rm -f $marker; exit 1" 0 1 2 3 13 15 touch -t $time $marker find . -type f -newer $marker rm -f $marker trap 0 
+11
Aug 6 2018-11-11T00:
source share

You can find every file that was created / modified on the last day, use this example:

 find /directory -newermt $(date +%Y-%m-%d -d '1 day ago') -type f -print 

to search for everything last week, use "1 week ago" or "7 days ago", whatever you want

+95
Sep 09 '13 at 19:23
source share

Maybe someone can use it. To find all files that have been changed recursively over a certain period of time, simply run:

 find . -type f -newermt "2013-06-01" \! -newermt "2013-06-20" 
+5
Dec 16 '16 at 11:05
source share

You can also do this without a marker file.

The% s format today is seconds from the era. find -mmin flag takes an argument in minutes, so divide the difference in seconds by 60. And "-" before age means searching for files whose last modification is less than age.

 time=1312603983 now=$(date +'%s') ((age = (now - time) / 60)) find . -type f -mmin -$age 

With newer versions of gnu find, you can use -newermt, which makes it trivial.

+4
Mar 08 '13 at 5:07
source share

Given the unix timestamp (seconds since the era) of 1494500000 , do:

 find . -type f -newermt "$(date '+%Y-%m-%d %H:%M:%S' -d @1494500000)" 

To grep these files for "foo":

 find . -type f -newermt "$(date '+%Y-%m-%d %H:%M:%S' -d @1494500000)" -exec grep -H 'foo' '{}' \; 
+2
May 13 '17 at 4:16
source share

So, there is another way (and it is somewhat tolerated _

 (python <<EOF import fnmatch import os import os.path as path import time matches = [] def find(dirname=None, newerThan=3*24*3600, olderThan=None): for root, dirnames, filenames in os.walk(dirname or '.'): for filename in fnmatch.filter(filenames, '*'): filepath = os.path.join(root, filename) matches.append(path) ts_now = time.time() newer = ts_now - path.getmtime(filepath) < newerThan older = ts_now - path.getmtime(filepath) > newerThan if newerThan and newer or olderThan and older: print filepath for dirname in dirnames: if dirname not in ['.', '..']: print 'dir:', dirname find(dirname) find('.') EOF ) | xargs -I '{}' echo found file modified within 3 days '{}' 
0
Oct 19 '16 at 23:47
source share



All Articles