hwclock Command in Linux: Read and Sync the Hardware Clock
The hwclock command on Linux can be used to read the hardware clock or update the hardware clock with the system clock and vice-versa.
As mentioned at the beginning of the chapter, computers keep two clocks. One called the hardware clock, is connected when the system is idle, and is maintained by a quartz crystal and a battery when the computer is off. This battery is capable of keeping the clock running even when disconnected from the power grid for a long time.
When the computer is turned on, Linux reads the hardware clock to update its system clock. It's common for there to be a small difference between these two clocks.
The hwclock command has the following options:
- -r: displays the hardware clock time with the local time zone;
- -s: sets the system clock with the time from the hardware clock;
- -w: sets the hardware clock with the time from the system clock;
- -c: compares the hardware clock and system clock times every 10 seconds;
- --adjust: adds or subtracts time from the hardware clock to compensate for frequency drift;
Examples:
# hwclock -chw-time system-time freq-offset-ppm tick1571594417 1571594417.0114231571594427 1571594427.012649 123 1
To set the hardware clock with the system clock:
# hwclock -w
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.