The Hwclock command, which is the same command as the Clock command, is used primarily to query and set the hardware clock (query and set the hardware clock (RTC)). Rtc=real time Clock, which is the hardware clock. There are two kinds of clocks, such as hardware clock and system clock, in Linux. The hardware clock is the clock device on the motherboard, which is usually the clock that can be set on the BIOS screen. The system clock refers to the clock in the kernel. All Linux-related instructions and functions are programmed to read the system clock. Because there are two different clocks, there is a difference between them. Depending on the parameter settings, the Hwclock command either synchronizes the hardware clock to the system clock or synchronizes the system clock to the hardware clock.
In terms of the relationship between the system clock and the hardware clock, the Web is divided into two types:
The first: When Linux starts, the hardware clock reads the settings of the system clock, and then the system clock is independent of the hardware.
Second: When Linux starts, the system clock reads the hardware clock settings, and then the system clock runs independently.
What is the right one? Perform a man hwclock can see there is a paragraph:
Man Hwclock wrote
The System is the time of the matters. The Hardware Clock ' s basic purpose in a Linux system was to keep time
When Linux was not running. Initialize the System time to the time from the Hardware Clock time Linux
Starts up, and then never use the Hardware Clock again. Note that on DOS, for which ISA is designed, the
Hardware Clock is the only real time clock.
This paragraph shows that the second is correct, and the first argument is wrong. But most of the online articles are the first kind of argument, so that the network, although good, to pay attention to screening.
Man Hwclock wrote
It is important, the System time not has any discontinuities such as would happen if you used the date (1L)
Program to set it while the system is running. You can, however, does whatever you want to the Hardware Clock
While the system was running, and the next time Linux starts up, it would do so with the adjusted time from the
Hardware Clock.
If the system time is modified with the date command, the hardware clock is not automatically modified, so the system clock is also taken from the hardware clock the next time the system restarts, and the date setting time is not valid. This is probably the reason why you need to hwclock commands.
Common parameters
-R,--show read and print the hardware clock (read hardware clock and print result)
-S,--hctosys synchronizes the hardware clock to the system clock (set the time from the hardware clock)
-W,--SYSTOHC synchronizes the system clock to the hardware clock (set the hardware clock to the current system time)
Using the example example one Hwclock command with the Clock command is a thing
[[email protected] ~]# type-a hwclock
Hwclock is/ Sbin/hwclock
Hwclock is/usr/sbin/hwclock
[[email protected] ~]#
[Email protected] ~]# type-a clock
Clock Is/sbin/clock
[Email protected] ~]# ls-l/sbin/clock
lrwxrwxrwx 1 root root 7 08-13 00:14/sbin/clock-Hwclock
[Email protected] ~]#
Example two display hardware clocks
[Email protected] ~]# hwclock
November 06, 2010 Saturday 21:09 28 sec -0.134840 seconds
[Email protected] ~]# hwclock-r
November 06, 2010 Saturday 21:09 33 sec -0.469123 seconds
[Email protected] ~]# hwclock--show
November 06, 2010 Saturday 21:09 45 sec -0.127548 seconds
[Email protected] ~]#
Example three modified date and synchronized to hardware clock
[[email protected] ~]# date
November 06, 2010 Saturday 21:11:57 CST
[[email protected] ~]# <== format mmddhhmm, which is the day of the month
November 06, 2010 Saturday 21:12:00 CST
[[email protected] ~]# hwclock
November 06, 2010 Saturday 21:12 13 seconds - 0.648818 seconds
[[email protected] ~]#
Note: To make the system time accurate, it is best to use NTP mode.
Example four use the Ntpdate command to synchronize time from the network, then synchronize to the hardware clock
The ntpdate command is a command that uses the NTP protocol to synchronize time from the network. Ntp=network Time Protocol Network Timing protocol.
[Email protected] ~]# ntpdate 0.rhel.pool.ntp.org
6 Nov 21:17:55 ntpdate[4829]: Step time Server 123.146.124.28 offset-1.025258 sec
[[email protected] ~]# date
Saturday, November 06, 2010 21:17:59 CST
[Email protected] ~]# hwclock-w
[Email protected] ~]#
This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1855438
Hwclock of Linux commands I used-querying and setting hardware clocks