The purpose of this tutorial is to change the hardware clock in Linux. You may have wondered how your Linux system always has the correct date and time when you start up your computer, even if it does not have internet access. How is the computer keeping track of time even when it is powered off?
Computer motherboards have a small battery, which continues powering the hardware clock even when the computer is completely turned off and disconnected from power. The hardware clock is always ticking, unless your motherboard battery dies. The hardware time is also used to display the correct time in BIOS, which does not have access to the operating system or internet in order to find the right time.
Of course, modern time keeping systems on Linux will consult time servers to keep your system clock synchronized down to the correct millisecond. This is different from the hardware clock, and is also how your system knows to change time in order to observe Daylight Savings Time or synchronize to a different time zone while traveling.
In this tutorial, you will see how to view the hardware clock time on Linux, and adjust the time of it on the command line.
In this tutorial you will learn:
- How to view hardware clock time
- How to change hardware clock
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux system|
|Software||hwclock (default command)|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Change hardware clock in Linux
hwclockLinux command is used to view and change the hardware clock time. In order to get started with this command, open a terminal on your system and use the appropriate command belows to interact with your system’s hardware clock.
Note that your
hwclock commands will need to be executed with root permissions.
- You can view the hardware clock time by simply typing the
hwclockcommand and no further options. The
--showoptions can also be used.
$ sudo hwclock 2021-12-19 00:00:02.224187-05:00
Ideally, this time should reflect the same as your system time (the time that is displayed when you type the
- If your system time is different than your hardware clock time, you can use the
--systohcoption to change the hardware clock to the current system clock time.
$ sudo hwclock --systohc
- It also works the other way around. To set the system clock time from the hardware clock use the
$ sudo hwclock --hctosys
- What if we want to set the hardware clock to some time that we specify manually? To do so, we will use the
--dateoptions, along with the following command syntax.
$ sudo hwclock --set --date="12/19/21 15:48:07"
This command would set the hardware clock to 15:48:07 on December 19, 2021.
You can always use the man command to read more about the hwclock command and its official documentation. Click the previous link to see how to open the manual pages for any command on a Linux system.
In this tutorial, we saw how to change the hardware clock on a Linux system by using the
hwclock command. This includes setting the hardware clock to match your system clock, or setting the hardware clock to some arbitrary date and time. There are more
hwclock options available, which you can read about on the manual page, but this is one of those commands that you probably will not need very often.