hwclock command in Linux with examples
Last Updated :
10 Oct, 2024
hwclock also called Real Time Clock (RTC), is a utility for accessing the hardware clock. The hardware clock is independent of the OS(operating system) you use and works even when the machine is shut down. The hardware clock is also called a BIOS clock. A user can also change the date and time of the hardware clock from the BIOS.
The hardware clock stores the values of the second, minute, hour, day, month, and year. The hwclock utility saves its settings in the "/etc/adjtime" file, which is created when a user makes the first change.
Syntax
hwclock [function] [option...]
Key Functions of the hwclock Command
1. -r, --show
Displays the current time stored in the hardware clock (RTC).
Example:
sudo hwclock -r
2. --get
Displays the drift-corrected RTC time.
Example:
sudo hwclock --get
3. --set
Sets the hardware clock to a specified date and time. You must provide the date using the --date option.
Example:
sudo hwclock --set --date="2024-10-10 15:45:00"
4. -s, --hctosys
Syncs the system time to match the hardware clock.
Example:
sudo hwclock -s
5. -w, --systohc
Updates the hardware clock to match the system clock. This is the reverse of --hctosys.
Example:
sudo hwclock -w
6. --systz
Sends the timescale configurations (like UTC or local time) to the kernel.
7. -a, --adjust
Adjusts the hardware clock to account for systematic drift based on the drift information stored in the "/etc/adjtime" file.
8. --predict
Predicts the drift-adjusted RTC time based on the given date.
Common Options in the hwclock Command
Option | Description |
---|
-u, --utc | Shows that the RTC (Real Time Clock) timescale is set to UTC. |
---|
-l, --localtime | Shows that the RTC timescale is set to Local Time. |
---|
-D, --debug | Displays detailed debug information based on the demands of the hwclock command. |
---|
-V, --version | Displays the version information of the hwclock utility and exits. |
---|
-h, --help | Displays a help text with an overview of the available options and exits the command. |
---|
Note: You should run the hwclock command with sudo privileges to make changes to the hardware clock or view the current RTC time.
Examples of Using the hwclock Command
1. To display the Hardware Clock Date and Time:

2. Using adjust function:

3. Using debug option to get the debug information:

Conclusion
The hwclock utility is an essential tool for managing hardware clock settings in Linux. If you're adjusting for drift, syncing system time, or simply checking the current RTC time, mastering the hwclock command can help you maintain accurate and reliable timekeeping on your Linux machine. With easy-to-use functions and options, it's a must-know utility for any Linux user or system administrator.
Similar Reads
hash command in Linux with examples The `hash` is a command in Linux that helps in managing the hash table. It facilitates with mapping the names of executable files to their locations on disk. It helps in speeds uping the commands execution by remembering paths of frequently used commands. It uses the `hash` to view hashed commands (
5 min read
hdparm command in Linux with Examples "hdparm" (i.e., hard disk parameter) is one of the command line programs for Linux that is used to handle disk devices and hard disks. With the help of this command, you can get statistics about the hard disk, alter writing intervals, acoustic management, and DMA settings. It can also set parameters
4 min read
Head Command in Linux With Examples Need to quickly view the beginning of a file in Linux? The head command is your best option. This essential command-line tool enables users, developers, and system administrators to preview the start of log files, configuration files, CSV datasets, and other text documents in seconds.The head comman
6 min read
help Command in Linux with examples If youâre new to the Linux operating system and struggling with command-line utilities, the help command is one of the first tools you should learn. As its name suggests, the 'help' command provides detailed information about built-in shell commands, making it an essential resource for beginners and
5 min read
hexdump command in Linux with examples The 'hexdump' command in Linux is a versatile utility used to display file content or data from standard input in a human-readable format. It is invaluable for programmers and system administrators for debugging binary data, analyzing file structures, and verifying data integrity. Here we will get a
5 min read
How to Display Command History in Linux | history Command The history command in Linux is essential for terminal users, enabling them to view, search, and manipulate previously executed commands. Now, mastering this Linux command allows for efficient commands of commands, automation of repetitive tasks, and troubleshooting without the need to retype length
3 min read
host command in Linux with examples host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more s
2 min read
hostid command in Linux with examples hostid is a command in Linux that is used to display the Host's ID in hexadecimal format. It provides a quick and straightforward way to retrieve the host ID, allowing administrators to associate it with software licenses or perform system-specific operations. Syntax of `hostid` command in Linuxhost
1 min read
hostname command in Linux with examples hostname command in Linux is used to obtain the DNS (Domain Name System) name and set the system's hostname or NIS (Network Information System) domain name. A hostname is a name given to a computer and attached to the network. Its main purpose is to uniquely identify over a network. Syntax of the `h
5 min read
hostnamectl command in Linux with Examples hostnamectl command provides a proper API used to control Linux system hostname and change its related settings. The command also helps to change the hostname without actually locating and editing the /etc/hostname file on a given system. Syntax: hostnamectl [OPTIONS...] COMMAND .... Where COMMAND c
2 min read