1

I'm trying to use

touch -d '20 seconds ago' file.txt

Which works in Ubuntu, but not in Alpine. Anybody knows if there's an additional package that does this, or is it not supported by Alpine itself?

EDIT:

# touch --help
BusyBox v1.28.4 (2018-12-06 15:13:21 UTC) multi-call binary.
1

2 Answers 2

1

On Alpine Linux, touch is indeed symlinked to BusyBox.

For GNU touch, install the GNU coreutils package, which provides /bin/touch:

apk add coreutils

2

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).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .