Given a time_t:
⚡ date -ur 1312603983
Sat 6 Aug 2011 04:13:03 UTC
I'm looking for a bash one-liner that lists all files newer. The comparison should take the timezone into account.
Something like
find . --newer 1312603983
But with a time_t instead of a file.
You can find every file what is created/modified in the last day, use this example:
for finding everything in the last week, use '1 week ago' or '7 day ago' anything you want
This is a bit circuitous because
touch
doesn't take a rawtime_t
value, but it should do the job pretty safely in a script. (The-r
option todate
is present in MacOS X; I've not double-checked GNU.) The 'time' variable could be avoided by writing the command substitution directly in thetouch
command line.Given a unix timestamp (seconds since epoch) of
1494500000
, do:To grep those files for "foo":
Assuming a modern release,
find -newermt
is powerful:or, if you want to specify a
time_t
(seconds since epoch):For reference,
-newermt
is not directly listed in the man page for find. Instead, it is shown as-newerXY
, whereXY
are placeholders formt
. Other replacements are legal, but not applicable for this solution.From
man find -newerXY
:So the following are equivalent to the initial example:
The
date -d
(andfind -newermt
) arguments are quite flexible, but the documentation is obscure. Here's one source that seems to be on point: Date input formatsYou can also do this without a marker file.
The %s format to date is seconds since the epoch. find's -mmin flag takes an argument in minutes, so divide the difference in seconds by 60. And the "-" in front of age means find files whose last modification is less than age.
With newer versions of gnu find you can use -newermt, which makes it trivial.
So there's another way (and it is portable to some extent_