The hwclock
command is used in Linux systems to display and set the hardware clock, which is also known as the Real Time Clock (RTC). The hardware clock is a clock that runs independently of the operating system and is used to keep track of time when the system is powered off. The hwclock
command is a useful tool for Linux system administrators to synchronize the system time with the hardware clock, or to set the hardware clock to a specific time.
Overview
The hwclock
command can be used to display the current date and time of the hardware clock or to set the hardware clock to a specific date and time. The command can also be used to synchronize the system time with the hardware clock or to adjust the time zone of the hardware clock.
Displaying the hardware clock time
To display the current date and time of the hardware clock, simply run the hwclock
command with no options:
$ hwclock
This will output the date and time of the hardware clock in the format of YYYY-MM-DD HH:MM:SS
.
Setting the hardware clock time
To set the hardware clock to a specific date and time, use the -w
option followed by the date and time in the format of YYYY-MM-DD HH:MM:SS
. For example, to set the hardware clock to January 1, 2022 at 12:00:00 PM, run the following command:
$ sudo hwclock -w --date="2022-01-01 12:00:00"
Note that the hwclock
command requires root privileges to set the hardware clock.
Synchronizing system time with hardware clock
To synchronize the system time with the hardware clock, use the -s
option:
$ sudo hwclock -s
This will set the system time to the time of the hardware clock.
Adjusting the time zone of the hardware clock
To adjust the time zone of the hardware clock, use the -z
option followed by the time zone name. For example, to set the time zone of the hardware clock to US Eastern Time, run the following command:
$ sudo hwclock -z EST
Options
The following table lists all available options for the hwclock
command:
Option | Description |
---|---|
-r , --show |
Display the current date and time of the hardware clock. |
-w , --systohc |
Set the hardware clock to the current system time. |
-s , --hctosys |
Set the system time to the time of the hardware clock. |
-z , --timezone |
Set the time zone of the hardware clock. |
-l , --localtime |
Treat the hardware clock as local time instead of UTC. |
-u , --utc |
Treat the hardware clock as UTC instead of local time. |
-f , --file |
Use a specific file instead of the default /dev/rtc . |
-h , --help |
Display help information. |
-V , --version |
Display version information. |
Troubleshooting tips
If you encounter issues with the hwclock
command, try the following troubleshooting tips:
- Ensure that you have root privileges when running the command.
- Check that the hardware clock is functioning correctly.
- Verify that the time zone is set correctly.
Notes
- The
hwclock
command is typically used in conjunction with thedate
command to manage the system time. - The hardware clock is typically set to UTC time and the system time is adjusted based on the time zone.
- The location of the hardware clock device file may vary depending on the system configuration.