How to sync Hardware Clock in Linux using hwclock

Posted on 9:19 PM by Bharathvn

Anyone can use the hwclock command to view hardware clock settings; however,
you must have root privileges to change those settings. To use hwclock to view the
current time from your computer’s hardware clock, type the following:

$ hwclock -r Display current hardware clock settings
Sun 12 Aug 2007 03:45:40 PM CDT -0.447403 seconds

Even if your hardware clock is set to UTC time, hwclock displays local time by default.If your system time strays from your hardware clock (for example, if you tried some of the date commands shown previously), you can reset your system clock from your hardware clock as follows:

$ sudo hwclock --hctosys Reset system clock from hardware clock

Likewise if your hardware clock is set incorrectly (for example, if you replaced the
CMOS battery on your motherboard), you can set the hardware clock from your system clock as follows:

# hwclock --systohc Reset hardware clock from system clock

Over time your hardware clock can drift. Because the clock tends to drift the same
amount each day, hwclock can keep track of this drift time (which it does in the
/etc/adjtime file). You can adjust the hardware clock time based on the adjtime file
as follows:

$ sudo hwclock --adjust Adjust hardware clock time for drift

To set the hardware clock to a specific time, you can use the --set option. Here is an example:

$ sudo hwclock --set --date=”3/18/08 18:22:00” Set clock to new date/time

In this example, the hardware clock is set to March 18, 2008 at 6:22 p.m. This update
does not immediately affect the system clock