Chris
Chris

Reputation: 1697

find and number of days range

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??

Upvotes: 3

Views: 5953

Answers (1)

Diego Sevilla
Diego Sevilla

Reputation: 29021

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.

Upvotes: 12

Related Questions