Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

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

GNU date(1) understands the %N format spec, which outputs nanoseconds, so:

$ date +%H:%m:%S.%N

outputs 19:10:03.725196000

BSD date doesn't understand %N. How can I print the current time with sub-second precision on OS X?

share|improve this question
up vote 5 down vote accepted

As you said, BSD date doesn't support %N. So the straightforward solution is to download GNU's date and install it to either ~/bin or /usr/local/bin and call that when you need to use %N.

However, I would not advise replacing the version that ships with your mac with the new one. Most of these coreutil programs are written such that their output can be understood by other programs, not necessarily humans. So reliability in output is a necessity. There might be several scripts in your mac that parse the output of BSD's date and any possible changes introduced by replacing with GNU's might or might not break things.

The simplest way to do this safely on a mac is to use homebrew and install coreutils.

brew info coreutils
coreutils 8.16
==> Caveats
All commands have been installed with the prefix 'g'.

The GNU equivalent will be named grate and is located in /usr/local/Cellar/coreutils/8.16/bin/. You can also set an alias in your .bashrc or its equivalent as

alias date='gdate'
share|improve this answer

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.