Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
43 views
43 views

I'm trying to create a timestamp with nanosecond precision on Alpine Linux. On Debian systems I'd use this command:

date +'%F %T.%N'

However, on Alpine the escape sequence %N doesn't seem to be supported, because I'm getting an empty string instead of the nanoseconds portion:

me@localhost:~$ date +'%F %T.%N'
2024-01-31 14:51:58.
in Scripting
by (125)
3 20 38
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

Alpine Linux by default uses busybox. For nanosecond precision you need to install the coreutils package:

root@alpine:~# ls -al /bin/date
lrwxrwxrwx    1 root     root            12 Jan 26 17:53 /bin/date -> /bin/busybox
root@alpine:~# date +'-%N-'
--
root@alpine:~# apk add coreutils
fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.19/community/x86_64/APKINDEX.tar.gz
(1/8) Installing coreutils-env (9.4-r2)
(2/8) Installing coreutils-fmt (9.4-r2)
(3/8) Installing coreutils-sha512sum (9.4-r2)
(4/8) Installing libacl (2.3.1-r4)
(5/8) Installing libattr (2.5.1-r5)
(6/8) Installing skalibs (2.14.0.1-r0)
(7/8) Installing utmps-libs (0.1.2.2-r0)
(8/8) Installing coreutils (9.4-r2)
Executing busybox-1.36.1-r15.trigger
OK: 9 MiB in 23 packages
root@alpine:~# ls -al /bin/date
lrwxrwxrwx 1 root root 20 Jan 31 13:56 /bin/date -> ../usr/bin/coreutils
root@alpine:~# date +'-%N-'
-402980617-
by (125)
3 20 38
edit history
...