Score:4

Can find's -newermt accept epoch time?

cn flag

I seek to find files made after a specific time similar to how this command does it:

find . -type f -newermt '1/30/2017 0:00:00'

except instead of a date, and time, string, I need the time stamp to be in epoch time as read from the EPOCHSECONDS system variable. Can this be done? Or will it be necessary to convert EPOCHSECONDS to a date and time string?

I am asking because in a shell script I need to set a variable value equal to EPOCHSECONDS, do some commands that will make changes to unknown files, and then use the find command to see what files those commands changed.

Steve Summit avatar
us flag
It might be more straightforward to just touch a temporary file, do your commands, then find files simply `-newer` than the temporary file.
Score:8
hr flag

Yes it can.

The -newerXY entry of man find tells us that

Time specifications are interpreted as for the  argument
to  the -d option of GNU date.

and from the info 'date input formats' node:

29.9 Seconds since the Epoch

If you precede a number with ‘@’, it represents an internal timestamp as a count of seconds. The number can contain an internal decimal point (either ‘.’ or ‘,’); any excess precision not supported by the internal representation is truncated toward minus infinity. Such a number cannot be combined with any other date item, as it specifies a complete timestamp.

So for example

find . -type f -newermt @1485752400

or

secs=$(date +%s -d '1/30/2017 0:00:00')
find . -type f -newermt "@$secs"
Stephen avatar
cn flag
Thank you for your reply. The epoch time I need to pass to find will be stored in a variable. The example you have given uses a numeric literal. By what syntax can a variable containing an epoch time value be passed to find? Can this variable be prefixed by @ just as the literal is in your example?
hr flag
@Stephen yes it can - see edit
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.