Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

time

System time and the hardware clock

  • The kernel maintains the system clock, which is the clock that is consulted when you run commands like date. You can also update the system clock using the date command. However, you shouldn’t as you will never get the time exactly right.
  • PC hardware has a battery backed Real Time Clock (RTC). The kernel usually sets it’s time based on the RTC at boot. You can reset the system time to the current time of the RTC using hwclock. Keep your hardware clock in UTC to avoid any trouble with time zones or daylight savings time. You can set the RTC to your Kernel’s UTC clock using this command: hwclock --systohc --utc
  • The kernel is very bad at keeping time. Because Linux systems will go days, months, or even years on a single boot, they typically will experience time drift. Becuase of this, you should configure the system clock to use NTP
  • The kernel’s system clock represents the current time as the number of seconds since 12 AM Midnight, January 1st 1970 UTC. To see this number at the moment, run date +%s
  • The time zone files on your system are in /usr/share/zoneinfo

Network Time Protocol (NTP)

  • NTP client services were once handled by an NTP daemon, but systemd has long since replaced this with a package named timesyncd.
  • timesyncd can be controlled using /etc/systemd/timesyncd.conf
  • If your machine does not have a persistent internet connection, you can use a daemon like chronyd to maintain the time during disconnects