1

I need to find files modified in August. Here's my portion of the command that narrows down the modification time. This works, but it seems to be missing some files. I'm guessing this is missing files modified in a given hour or hour(s) because the numbers change depending on what part of the day that I run this script. I'm looking at the -mmin parameter but am struggling with how to exactly implement it. I'm looking for all files modified between Aug 1 - 31.

    $dayOfMonth = date("j");
    $daysLastMonth = date("t", strtotime('-1 month'));
    $secondsSinceMidnight = time() - strtotime('00:00');
    $secondsUntilMidnight = (60*60*24) - $secondsSinceMidnight;
    $commandAppend = " -name '*.pdf' -mtime -".($dayOfMonth+$daysLastMonth)." -mtime +".($dayOfMonth)." | wc -l";
Ben
  • 3,630
  • 17
  • 62
  • 93

2 Answers2

1

You could to something with the -newer switch

touch -d "01 AUG 2012" start
touch -d "31 AUG 2012 23:59:59" end
find /path -newer start -not -newer end

Which will find files that are newer than the file start and not newer that the file end

-newer file

          File was modified more recently than file.  If file  is  a  sym-
          bolic  link and the -H option or the -L option is in effect, the
          modification time of the file it points to is always used.
sudo find /home -newer start | wc -l
41597
sudo find /home -newer start -not -newer end | wc -l
41568
sudo find /home -newer end | wc -l
29
user9517
  • 114,104
  • 20
  • 206
  • 289
0

You can create two files using touch -t representing the start and end of your duration. Then, you can use find with -newer option. The detailed answered is here.

Khaled
  • 35,688
  • 8
  • 69
  • 98
  • That gives me the error `find: missing argument to `-exec'` when I run `find "/path-to-pdfs/" -name '*.pdf' -newer /script_files/tmpStartModificationTime ! -newer /script_files/tmpEndModificationTime -exec ls -s {}\;` – Ben Sep 27 '12 at 12:51