Is there a shell command in Linux to get the time in milliseconds?
On OS X, where date does not support the %N flag, I recommend installing coreutils using Homebrew. This will give you access to a command called gdate that will behave as date does on Linux systems.
brew install coreutils
For a more "native" experience, you can always add this to your .bash_aliases:
alias date='gdate'
Then execute
$ date +%s%N