Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On this system:

$ cat /etc/issue
Ubuntu 14.04.4 LTS \n \l
$ uname -a
Linux mypc 3.19.0-56-generic #62~14.04.1-Ubuntu SMP Fri Mar 11 11:03:33 UTC 2016 i686 i686 i686 GNU/Linux
$ apt-show-versions -r moreutils
liblist-moreutils-perl:i386/trusty 0.33-1build3 uptodate
moreutils:i386/trusty 0.50 uptodate

... I can use date with a nanosecond precision, no problem:

$ date +'%Y%m%d%H%M%S'
$ date +'%Y%m%d%H%M%S%N'

... however, if I use the same format string with moreutils' ts, the nanosecond precision fails:

$ ping google.com | ts '%Y%m%d%H%M%S%N'
20160327133829%N PING google.com ( 56(84) bytes of data.
20160327133829%N 64 bytes from arn06s07-in-f14.1e100.net ( icmp_seq=1 ttl=54 time=32.0 ms
20160327133830%N 64 bytes from arn06s07-in-f14.1e100.net ( icmp_seq=2 ttl=54 time=31.6 ms

Any way to get ts to show nano- (or micro-) second precision when prepending timestamps to stdin?

share|improve this question
up vote 5 down vote accepted

Starting from moreutils 0.31 %.S specifier is available, use it instead of %S :

ping google.com | ts '%Y%m%d-%H:%M:%.S'
20160327-15:01:11.361885 PING google.com ( 56(84) bytes of data.
20160327-15:01:11.362056 64 bytes from bud02s22-in-f206.1e100.net ( icmp_seq=1 ttl=57 time=26.3 ms
20160327-15:01:12.314243 64 bytes from bud02s22-in-f206.1e100.net ( icmp_seq=2 ttl=57 time=26.2 ms
20160327-15:01:13.315651 64 bytes from bud02s22-in-f206.1e100.net ( icmp_seq=3 ttl=57 time=26.3 ms
share|improve this answer
That's nice - great there is a solution; cheers @Tagwint! – sdaau Mar 27 at 12:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.