Linux clock Command
The Linux clock command is used to adjust the RTC time.
RTC is the built-in hardware time of the computer. Executing this command can display the current time, adjust the hardware clock time, set the system time to match the hardware clock time, or restore the system time to the hardware clock.
Syntax
clock [--adjust][--debug][--directisa][--getepoch][--hctosys][--set --date="<date and time>"][--setepoch --epoch=<>][--show][--systohc][--test][--utc][--version]
Parameter Description:
--adjust: The first use of the "--set" or "--systohc" parameter to set the hardware clock will produce a file named adjtime in the /etc directory. When these two parameters are used again to adjust the hardware clock, this file will record the difference between the two adjustments. When the clock command is executed with the "--adjust" parameter in the future, the program will automatically calculate the average value based on the record file and adjust the hardware clock time accordingly.
--debug: Displays detailed command execution process, useful for debugging or understanding program execution.
--directisa: Tells the clock command not to access the hardware clock through the /dev/rtc device file, but directly. This parameter is suitable for old computers with only ISA bus structure.
--getepoch: Displays the hardware clock epoch value in the system kernel to the standard output device.
--hctosys: Hardware Clock to System Time, sets the system time to match the hardware clock. Since this action will cause a comprehensive update of file access times, it is best to execute it at system startup.
--set--date: Sets the date and time of the hardware clock.
--setepoch--epoch=<year>: Sets the hardware clock epoch value in the system kernel, with the year represented by four digits.
--show: Reads the time from the hardware clock and presents it to the standard output device.
--systohc: System Time to Hardware Clock, stores the system time back to the hardware clock.
--test: Only tests, does not actually write the time to the hardware clock or system time.
--utc: Considers the time on the hardware clock as CUT, sometimes also referred to as UTC or UCT.
--version: Displays version information.
Examples
Get the current time
# clock // Get the current time
Display UTC time
# clock -utc // Display UTC time