Linux divides the clock into two types: the system clock and the hardware clock (Real time clock). System time refers to the clock in the current Linux kernel, while the hardware clock is the battery-powered motherboard hardware clock on the motherboard, which can be set in the BIOS "standard BIOS feture" entry. When Linux starts, the hardware clock reads the settings of the system clock, and then the system clock is independent of the hardware, so the system clock and hardware clock can be asynchronous, i.e. system time and hardware time can be different. From the Linux boot process, there is no conflict between the system clock and the hardware clock, but all commands in Linux are the system clock settings used.
In Linux, the commands used for clock viewing and setting are mainly date, hwclock, and clock. Date display and set the system clock, hwclock and clock are used to display and set the hardware clock, but hwclock and clock can be regarded as a command.
1 # Type-a hwclock2 hwclock is/sbin/hwclock3 hwclock is/usr/sbin/ Hwclock4 # type-a clock5 clock is/sbin/6ls -l/sbin/< C12>clock717 /sbin/clock-Hwclock
Here are examples of the use of date, hwclock (clock) respectively.
First, display and set the system clock
1#Date\ \ Display system time2Saturday, April 11, 2015 +: A: -CST3#Date-S'2015-04-11 13:15:15'\ \ Modify the system time4Saturday, April 11, 2015 -: the: theCST5 6 \ \ can also set the system time by the following method7#Date 041120252015.15\ \ month/day year. Seconds8Saturday, April 11, 2015 -: -: theCst
Second, display and set the hardware clock
1 \ \ Display hardware clock The following three commands are the same2 # Hwclock3April 11, 2000 Tuesday 13:24 35 seconds-0.109687seconds4# Hwclock-R5April 11, 2000 Tuesday 13:24 43 seconds-0.359613seconds6# Hwclock--Show7April 11, 2000 Tuesday 13:24 49 seconds-1.051616seconds8 9 \ \ Set Hardware clockTen# Hwclock--set--Date '2015-04-11 13:36:11' One# Hwclock--Show AApril 11, 2015 Saturday 13:36 16 seconds-0.797103Seconds
Three, clock synchronization, said before that the system clock and hardware clock is asynchronous, can be different. But sometimes you need to synchronize the two.
\ \ Synchronizes the system clock to the hardware clock \ \ Method 1 Clock-W# DateSaturday, April 11, 2015 -: $: -cst# clock2015 April 11 Saturday 13:41 18 seconds-0.437760seconds# Clock-W\ \ Synchronizes the system clock to the hardware clock # clock2015 April 11 Saturday 20:37 36 seconds-0.515922Seconds\\ Method 2 Clock--systohc# Clock--set--Date="08/16/2013 13:26:00"# clock2013 August 16 Friday 13:26 04 seconds-0.390867seconds#DateSaturday, April 11, 2015 -: A: -cst# Clock--systohc# clock2015 April 11 Saturday 20:43 18 seconds-0.094007seconds\\ synchronizing the hardware clock to the system clock # Clock--set--Date="08/16/2013 13:26:00" # clock2013 August 16 Friday 13:26 03 seconds-0.281525seconds#DateSaturday, April 11, 2015 -: $: -cst# Clock--hctosys \ Clock Sync #DateFriday, August 16, 2013 -: -: Acst# clock2013 August 16 Friday 13:26 25 seconds-0.406511Seconds
Finally, we synchronize the system clock with the network clock and then sync to the hardware clock
1# ntpdate0. rhel.pool.ntp.org2 OneApr -: -:Genevantpdate[5786]: Step TimeServer202.112.29.82Offset52100210.175926sec3#Date4Saturday, April 11, 2015 -: -: -CST5# clock-W6 # Clock7April 11, 2015 Saturday 13:48 30 seconds-0.750266Seconds
Use date, Hwclock, and clock commands to display and set clocks under Linux