This will work with busybox's touch
& date
without needing to install GNU coreutils:
touch -d@$(( $(date +%s) - 20 )) file.txt
This calculates the date from epoch time, subtracts 20 seconds, and passes that as the desired time for touch
to use.
I tested this with BusyBox 1.30.1 (via busybox touch -d@$(( $(busybox date +%s) - 20 )) file.txt
)
Also note that this will work with the GNU versions of those commands as well as almost any implementation of date
(GNU, BSD, OS X, BusyBox, etc), though POSIX date
does not specify %s
and POSIX touch
does not specify -d@epoch
(and BSD/OSX doesn't implement it).