Celebrate Our 22nd Anniversary with Huge Savings! Up to 70% Off

Explain the command "hwclock"

hwclock is a UNIX and Linux command for accessing the computer's hardware clock. This is the battery-powered clock on the system's motherboard.

The hardware clock is independent of the operating system and works even if the machine is shut down. It is also called a real-time clock (RTC) or BIOS clock.

A battery eliminates the need to reset the clock when the computer is powered back on if the computer loses power.

The hardware clock is also known as the BIOS clock. Users can also change the hardware clock date and time from BIOS. The time is recorded when the operating system loads. The time may or may not be set depending on the system's hardware clock. Alternatively, you can set the time according to a network time server.

A hardware clock is very different from a clock managed by the Linux kernel. It runs when the system is running and is independent of the operating system used, so it remains active even when the machine is off.

Hardware clock stores values for seconds, minutes, hours, days, months, and years. The hwclock utility saves its settings in the /etc/adjtime file. This file is created when the user makes the first change.

The hardware clock setting can be changed from BIOS. Users can also set and view the hardware time using the hwclock command.

Syntax:

hwclock [option...]

Options:

-r or -show: You can display the RTC time on standard output by using this option.

-set: Sets the hardware clock time according to -date.

-s: Option is used to set the Hardware Clock to the current system time.

-w: Sets the BIOS time based on the system time.

–adjust: Adjust the RTC to account for systematic drift.

=> Some useful commands of hwclock are as follows:

[1] hwclock -r used to view hardware clock date and time. The date and time can also be displayed using the -show option.

[2] Using the hwclock -w command, you can set the date and time of the hardware clock to the current system time. This will set the date and time of the hardware clock to the same time and date as the system clock.

The date command uses the Linux kernel's clock to determine the date and time.

[3] hwclock --set: You can manually set the hardware clock's date and time instead of copying the values from the system.

[4] Using the -s option, you can copy the hardware time to the system time if the hardware clock is correct but the system clock is not.

Both the -s and -hctosys options do the same thing.

 

[5] The system takes the time from the hardware clock when it starts. hwclock --adjust uses the /etc/adjtime file to control the adjustment.

[root@mail ~]# hwclock --adjust

/etc/adjtime contains three lines:

[root@mail ~]# cat /etc/adjtime

0.000000 1670022645 0.000000

1670022645

UTC

-> There are three values in the first row:

Systematic drift rate in seconds per day.

The number of seconds since 1969 UTC when the last adjustment was made.

0 only.

-> In the second row, the value is the same as the second value of the first row.

-> Either UTC or LOCAL is indicated on the third line.

[6] To view hwclock's version information, use hwclock -v.

[7] You can get more information about the hwclock by running hwclock -help.

[root@mail ~]# hwclock -help

If you wish to access hwclock, you will need to login to the server as root or the user with a sudo privilege.resultmayYou can see that.

 


Was this answer helpful?

« Back

chat