hwclock

Display and set hardware clock

Supplementary instructions

hwclock command is a hardware clock access tool. It can display the current time, set the hardware clock time and set the hardware clock to the system time. It can also set the system time to the hardware clock time.

There are two types of clocks in Linux: hardware clock and system clock. The hardware clock refers to the clock device on the motherboard, which is the clock that can usually be set in the BIOS screen. The system clock refers to the clock in the kernel. When Linux starts, the system clock will read the hardware clock settings, and then the system clock will operate independently. All Linux related commands and functions read the system clock settings.

grammar

hwclock(option)

Options

--adjust: Every time hwclock changes the hardware clock, it will be recorded in the /etc/adjtime file. Using the --adjust parameter, hwclock can estimate the hardware clock deviation based on previous records and use it to correct the current hardware clock;
--debug: Display detailed information when hwclock is executed;
--directisa: hwclock accesses the hardware clock from the /dev/rtc device by default. If access is not possible, this parameter can be used to directly access the hardware clock using I/O instructions;
--hctosys: Adjust the system clock to be consistent with the current hardware clock;
--set --date=<date and time>: Set the hardware clock;
--show: Display the time and date of the hardware clock;
--systohc: Adjust the hardware clock to be consistent with the current system clock;
--test: only tests the program without actually changing the hardware clock;
--utc: If you want to use Greenwich Mean Time, please add this parameter, hwclock will perform the conversion work;
--version: Display version information.

Example

Setting the hardware time depends on the operating system time. The specific method is as follows:

hwclock –systohc
hwclock --systohc –-utc

Using hwclock without any parameters, you can view the current hardware date and time.

hwclock

Check the clock file to confirm whether UTC is set:

cat /etc/default/rcS
UTC=yes

In some other versions of Linux (such as RebHat) you can view it like this:

cat /etc/sysconfig/clock
ZONE="America/Los_Angeles"
UTC=false
ARC=false