tl;dr
find root.d -type f -newermt "-7 days"
or
find root.d -type f -newermt "$(date -d "$(date)-7days")"
Tested with bash using:
Ubuntu |
Find |
23.04 |
4.9.0 |
22.04 |
4.8.0 |
20.04 |
4.7.0 |
also verified in macOS(darwin) zsh and bash
use the following to find out which versions you have
cat /etc/lsb-release
find --version
Assume the following directory structure and files with these relative modified timestamps
root.d/
├── file_c (-5 years)
└── level_1.d/
├── file_a (-45 minutes)
└── file_b (-1 second)
example 1
find all the files recursively in root.d with a modifed date "newer than" 10 minutes ago
NEWER_THAN="-10 minutes"
find root.d -type f -newermt "$NEWER_THAN"
result
root.d/
└── level_1.d
└── file_a
example 2
find all the files recursively in root.d with a modifed date "newer than" 10 hours ago and older than ("not newer than") 10 minutes ago
NEWER_THAN="-10 hours"
OLDER_THAN="-10 minutes"
find root.d -type f -newermt "$NEWER_THAN" -not -newermt "$OLDER_THAN"
result
root.d/
└── level_1.d
└── file_b
example 3
find all the files recursively in root.d with a modifed date older than ("not newer than") 10 days ago
OLDER_THAN="-10 days"
find root.d -type f -not -newermt "$OLDER_THAN"
result
root.d/
└── file_c
considerations
after a few simple tests, I am confident the comparisons are strictly greater/less not equal.
relevant discussion
another simlar discussion
-newerXY reference
Succeeds if timestamp X of the file being considered is
newer than timestamp Y of the file reference. The letters
X and Y can be any of the following letters:
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
find man page