Linux find: Select a Fixed UTC Modification-Time Window and Verify Its Boundaries
When a Linux file report covers a fixed period, define the two boundary instants and decide which boundary includes a file. GNU find‘s -newer comparison is strict: a file must be later than the reference timestamp. Combining a lower comparison with a negated upper comparison creates the interval start < mtime <= end.
This walkthrough follows the Leverage Lab Studios tutorial and its boundary-checking Short. The example uses five fictional files and fixed UTC reference times. It reads file timestamps without changing the system clock or modifying an existing real-data collection.
Define the interval before writing the command
The first example window starts at 2026-10-01 00:00:00 UTC and ends at 2026-10-02 00:00:00 UTC. The start is excluded and the end is included. The next window uses that same end instant as its excluded lower boundary.
| File | Modification time relative to the first start | First window? |
|---|---|---|
before.txt | One second before | No |
start.txt | Exactly at the start | No |
inside.txt | Twelve hours after | Yes |
end.txt | Exactly at the end | Yes |
after.txt | One second after the end | No; it belongs in the next window |
This is a boundary policy, not an assumption about how people describe a “day.” If your reporting system requires an inclusive start and exclusive end, use an implementation that tests that different policy explicitly rather than relabelling the command below.
1. Create an isolated practice folder
Use a new empty directory. Save the following as seed.py and run it with python3 seed.py. The relative paths deliberately keep the example inside that practice directory. Existing events or references folders cause this setup to stop rather than replace them.
from pathlib import Path
from datetime import datetime, timezone, timedelta
import os
start = datetime(2026, 10, 1, tzinfo=timezone.utc)
Path('events').mkdir()
Path('references').mkdir()
offsets = {
'before.txt': -1,
'start.txt': 0,
'inside.txt': 43200,
'end.txt': 86400,
'after.txt': 86401,
}
for name, seconds in offsets.items():
path = Path('events') / name
path.write_text(name + '\n')
stamp = int((start + timedelta(seconds=seconds)).timestamp()) * 1_000_000_000
os.utime(path, ns=(stamp, stamp))
for name, days in [('start.ref', 0), ('end.ref', 1), ('next.ref', 2)]:
path = Path('references') / name
path.touch()
stamp = int((start + timedelta(days=days)).timestamp()) * 1_000_000_000
os.utime(path, ns=(stamp, stamp))The aware UTC datetime establishes the reference instants. Setting the timestamps of these new fictional files is different from changing the machine’s clock. No real folder’s modification times should be rewritten to make a report pass.
2. Select the first window
This command is for GNU findutils on Linux. The -printf action is not a portable assumption for every operating system’s version of find.
find events -type f \
-newer references/start.ref \
! -newer references/end.ref \
-printf '%f\n' | LC_ALL=C sortThe first comparison requires a modification time strictly later than the start reference. The negated second comparison permits a time at or before the end reference. The expected sorted output is:
end.txt
inside.txtstart.txt is intentionally missing. end.txt is intentionally present. Test those exact-boundary cases instead of inferring the policy from a file somewhere in the middle.
3. Select the adjacent window
find events -type f \
-newer references/end.ref \
! -newer references/next.ref \
-printf '%f\n' | LC_ALL=C sortThe next result is only after.txt. The file exactly at the shared boundary appeared in the first window and does not appear again in the second. The two result sets do not overlap.
4. Check timestamps independently
The recorded practice checker compares each file’s st_mtime_ns with the two reference files using Python’s direct inequality lower < timestamp <= upper. It then checks the expected names, the absence of overlap and the unchanged fictional file contents. That independent comparison helps catch a command whose output looks plausible while its boundary policy is wrong.
For a real workflow, preserve the chosen reference instants with the report. A later rerun should use those saved instants rather than silently moving the window to “the last 24 hours.” A rolling duration and a named UTC reporting period answer different questions.
Limits to keep in mind
A modification timestamp describes the file’s recorded content-modification time. It is not an immutable activity log or necessarily the file’s creation time. Filesystem timestamp resolution and files changing while a scan runs also matter. For auditable or backup-sensitive jobs, define how to handle concurrent changes and keep the reference files outside the scanned data directory.
The example’s filenames are simple and contain no newlines. A production process that passes arbitrary filenames between tools should use NUL-delimited records where supported rather than assuming a newline always separates one filename.
For the timestamp comparison semantics, see the GNU findutils reference. Explore the tutorial collection for related demonstrations. If this report is part of a backup workflow, distinguish selecting files from proving their recovery; our backup guide and independent-copy strategy cover that wider context.
James Kennedy is a writer and product researcher at Drives Hero with a background in IT administration and consulting. He has hands-on experience with storage, networking, and system performance, and regularly improves and optimizes his home networking setup.




