The blog provides Network Security Tips, Tricks, How To/Procedures. Products and areas not limited to Firewalls, Security, Check Point, Cisco, Nokia IPSO, Crossbeam, SecurePlatform, SPLAT, IP Appliance, GAiA, Unix/Linux.

Linux/Unix - How To View Hardware Clock & Synchronize It With System Clock

In Linux/Unix based system, 'clock' command usually displays time from hardware clock while 'date' command display time from operating system clock. Actually '/bin/date' binary file is executed when 'date' command is issued.

Only in rare occasions, you would happen to notice major time difference between output of 'clock' command and 'date' command, that's hardware and operating system clocks respectively. Especially when Linux/Unix based system is configured to get time from NTP server, the operating system clock would get and display time from NTP server while hardware clock doesn't automatically get updated if time is changed in NTP server. For instance, NTP server sets it's clock an hour behind when day light saving applies, during this change hardware clock would not automatically gets updated.

This example would help manually synchronize hardware clock with operating system clock.

Syntax:

clock --systohc

Usage:

clock (or) hwclock [function] [options...]

Functions:
--help     show this help
--show     read hardware clock and print result
--set      set the rtc to the time given with --date
--hctosys  set the system time from the hardware clock
--systohc  set the hardware clock to the current system time
--adjust   adjust the rtc to account for systematic drift since
           the clock was last set or adjusted
--getepoch print out the kernel's hardware clock epoch value
--setepoch set the kernel's hardware clock epoch value to the
           value given with --epoch
--version  print out the version of hwclock to stdout



 

Options:
--utc        the hardware clock is kept in coordinated universal time
--localtime  the hardware clock is kept in local time
--directisa  access the ISA bus directly instead of /dev/rtc
--badyear    ignore rtc's year because the bios is broken
--date       specifies the time to which to set the hardware clock
--epoch=year specifies the year which is the beginning of the
             hardware clock's epoch value
--noadjfile  do not access /etc/adjtime. Requires the use of
             either --utc or --localtime


Example:

!! Operating system clock !!
[root@Linux]# date
Thu Feb 14 11:44:05 AEST 2015
[root@Linux]#


!! Hardware clock, an hour ahead of operating system clock !!
[root@Linux]# clock
Thu Feb 14 12:44:06 2015 -0.000266 seconds
[root@Linux]#


!! Set the hardware clock to the current operating system time !!
[root@Linux]# clock --systohc
[root@Linux]#


!! Now hardware clock is set to system time !!
[root@Linux]# date
Thu Feb 14 11:44:26 AEST 2015
[root@Linux]# clock
Thu Feb 14 11:44:27 2015 -0.000224 seconds
[root@Linux]#


Linux/Unix - How To View Hardware Clock & Synchronize It With System Clock Linux/Unix - How To View Hardware Clock & Synchronize It With System Clock Reviewed by Admin on 18:46:00 Rating: 5