0

How do I print the nanoseconds/milliseconds in bash's date command in OSX?

From bash date man page:

%N     nanoseconds (000000000..999999999)

On Debian:

$ date +%N
028481864

But on OSX shell, I get:

[$] date +%N
N
Cœur
  • 37,241
  • 25
  • 195
  • 267
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
  • It is not possible with the built-in `date`. – 2rs2ts Jul 30 '13 at 22:22
  • 1
    It is a duplicate, and I should just use `gdate`. Thanks. – Adam Matan Jul 30 '13 at 22:33
  • ...that said, a high-precision `date` in shell is kinda' silly, because the overhead of starting up an external `date` command is so large that by the time it's printed, it's no longer the time when the request was made. Makes much more sense to, say, pipe output from a shell script through a long-running program that adds timestamps; rather than starting up a new program to just calculate a single timestamp, and start it again whenever you want another one. – Charles Duffy Mar 25 '19 at 04:49
  • (Very new versions of bash have a lower-overhead way of printing dates in `printf '%(...)T'`; however, that one doesn't support nanoseconds either). – Charles Duffy Mar 25 '19 at 04:49

0 Answers0