find has good support for finding files the more modified less than X days ago, but how can I use find to locate all files modified after a certain date?

I can't find anything in the find man page to do this, only to compare against another files time or to check for differences between created time and now. Is making a file with the desired time and comparing against that the only way to do this?

link|improve this question

This would be better asked on SuperUser.com – Josh Brower Mar 16 '10 at 11:30
2  
I'm not going to close this: could be interesting for sysadmins as well. – splattne Mar 16 '10 at 13:41
The command is for part of a backup script, which grabs everything from /etc that was changed post-installation in our nightly backups. – DrStalker Mar 18 '10 at 1:05
feedback

5 Answers

up vote 4 down vote accepted

If you have only '-newer file' then you can take this workaround:

touch -t 201003160120 some_file
find . -newer some_file

man touch:

  -t STAMP
          use [[CC]YY]MMDDhhmm[.ss] instead of current time

Assuming that your touch has this option (mine is touch 5.97).

link|improve this answer
feedback

No, you can use a date/time string.

From man find:

-newerXY reference
Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select which time belonging to how reference is used for the comparison.

          a   The access time of the file reference
          B   The birth time of the file reference
          c   The inode status change time of reference
          m   The modification time of the file reference
          t   reference is interpreted directly as a time

Example:

find -newermt "mar 03, 2010" -ls
find -newermt yesterday -ls
find -newermt "mar 03, 2010 09:00" -not -newermt "mar 11, 2010" -ls
link|improve this answer
1  
I'm using Centos 5.2, which uses GNU find version 4.2.27, and it does not support -newermt or any -newer parameter other than "-newer file" – DrStalker Mar 16 '10 at 7:08
GNU findutils 4.3.3 and newer supports -newerXY according to savannah.gnu.org/bugs/?11668 – Philip Durbin Jun 29 '10 at 13:58
feedback
find <dir> -mtime -20

this find command will find files modified within the last 20 days.

  • mtime -> modified (atime=accessed, ctime=created)
  • -20 -> lesst than 20 days old (20 exactly 20 days, +20 more than 20 days)

You acan add additional limitations like:

find <dir> -mtime -20 -name "*.txt"

the same as before, but only finds files ending with '.txt'.

link|improve this answer
feedback

You could use a script like this

#!/bin/bash

if [ $# -ne 1 ];then
  when="today"
else
  when=` date -d "$1" +"%s" `
fi
now=`date +"%s"`

seconds=`echo "$when - $now" | bc`
minutes=`echo "$seconds / 60 " | bc `

find . -cmin $minutes -print

Save it in your $PATH as "newerthan" and make it executable.

Then you can find file modified after a certain date like this:

newerthan "2010-03-10"

or

newerthan "last year"

or

newerthan "yesterday"

That should do what you want. I don't think there is a built in way to achieve this otherwise.

link|improve this answer
It's not necessary to use bc for integer math, Bash can do it: ((seconds = when - now)), the format argument to date should have a plus date +%s and some systems may not have date -d – Dennis Williamson Mar 16 '10 at 11:02
This is for Centos 5.2. Which does have -d. Useful to know about the integer maths though. – Richard Holloway Mar 16 '10 at 11:29
feedback

if your date is formatted such that its ok for comparison,

mydate=201003160120
find . -type f -printf "%AY%Am%Ad%AH%AM%AS/:%p\n" | awk -vd="$mydate" -F'/:' '$1 > d{ print $2 }'
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.