3

I tried to code in bash an archiving script but I can't seem to get find() working with an interval in number of days.

The ranges I need to code are

  1. files last modified between today and 31 days old. This works:

find . -name "*.VER" -mtime -31 -exec mv '{}' /opt/html/31';' -print

  1. files last modified between 31 days and 62 days old. This does not work:

find . -name "*.VER" -mtime -31 -mtime -62 -exec mv '{}' /opt/html/62 ';' -print

  1. files last modified between 62 days and 93 days old
  2. files last modified between 93 days and 124 days old
  3. ...you get the idea (up to year)....

Is there a way to code my find() command to use a number of days range??

Chris
  • 1,667
  • 6
  • 34
  • 52
  • Possible duplicate of [How to find the difference in days between two dates?](https://stackoverflow.com/questions/4946785/how-to-find-the-difference-in-days-between-two-dates) – jww Apr 29 '18 at 21:22

1 Answers1

12

I think you have to change the logic of + and - in the times:

find . -name "*.VER" -mtime +31 -mtime -62 -exec mv '{}' /opt/html/62 ';' -print

This tells: files with a mtime greater than 31 days but less than 61 days.

Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87