I'm trying to think of a command or a script that can locate the NEWEST file in a directory and print it's path ONLY IF the file is older than 'X' hours.
The idea behind this is the script to return value (the path of the newest file) only if it's older than 'X' hours. If it returns nothing, it should mean that the newest file is younger than the specified time.
$EPOCHSECONDS
is from zsh (renamed from$SECS
in 2003). Added to bash in 5.0 from 2019. With older versions ofbash
, you can useprintf %T
(which it borrowed from ksh93), or you can also usedate +%s
. – Stéphane Chazelas Sep 09 '22 at 22:30