What is the command to update time and date from internet
This is a nice little code I found to update your time in case you have issues with ntp
:
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
You can do so with e.g. sudo ntpdate time.nist.gov
. Other servers include time.windows.com
, etc.
http://www.pool.ntp.org/ lists time servers around the world.
As of 2018 with a fresh installed Ubuntu 16.04 LTS, running sudo ntpdate time.nist.gov
gives:
sudo: ntpdate: command not found
This is because (official source):
ntpdate
is considered deprecated in favour oftimedatectl
and thereby no more installed by default.
Instead do this to force the sync to happen now:
sudo timedatectl set-ntp off
sudo timedatectl set-ntp on
In my case I was running a Ubuntu on a virtualbox and had saved the machine state so when I started the instance back up again it did not automatically sync the clock since there was no boot event to trigger the sync. So the time was still showing what it was the last time I was running the virtual box.