hwclock

system administrationLinux
The hwclock command is one of the most frequently used commands in Linux/Unix-like operating systems. hwclock Query or set the hardware clock (RTC)

Quick Reference

Command Name:

hwclock

Category:

system administration

Platform:

Linux

Basic Usage:

hwclock [options] [arguments]

Common Use Cases

    Syntax

    hwclock [options]

    Options

    Option Description
    -r, --show Read and display the hardware clock
    --get Read hardware clock and print drift-corrected result
    --set Set the hardware clock to the time given with --date
    --hctosys Set the system time from the hardware clock
    --systohc Set the hardware clock from the system time
    --adjust Adjust the RTC to account for systematic drift
    --utc The hardware clock is kept in UTC
    --localtime The hardware clock is kept in local time
    --date=date_string Specifies the time to which to set the hardware clock
    --update-drift Update drift factor in /etc/adjtime
    --noadjfile Do not use /etc/adjtime
    --adjfile=file Use specified file instead of /etc/adjtime
    --test Do not update anything, just show what would happen
    --debug Display more details about what is being done
    --help Display help information and exit
    --version Output version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the hwclock command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    sudo hwclock
    Display the current time from the hardware clock.
    sudo hwclock --systohc
    Set the hardware clock from the system time.
    sudo hwclock --hctosys
    Set the system time from the hardware clock. # Advanced Examples Advanced sudo hwclock --set --date="2023-01-15 14:30:00" Set the hardware clock to a specific date and time. sudo hwclock --systohc --utc Set the hardware clock from the system time, saving in UTC format. sudo hwclock --show --debug Show hardware clock time with debugging information. sudo hwclock --adjust Adjust the hardware clock by applying drift correction factors.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The hwclock command is used to access the hardware clock, also known as the Real-Time Clock (RTC) or CMOS clock. This hardware component continues to track time even when the computer is powered off, ensuring accurate timekeeping between system boots. Key features of hwclock: 1. Hardware Clock Access: hwclock provides direct access to read and set the hardware clock, which is separate from the system clock maintained by the kernel. 2. System Time Synchronization: The command can synchronize the system time with the hardware clock (--hctosys) or update the hardware clock from the system time (--systohc), which is essential for maintaining accurate time. 3. Time Format Options: hwclock supports both UTC (Coordinated Universal Time) and local time formats for the hardware clock, with UTC generally recommended to avoid issues with daylight saving time changes. 4. Drift Correction: The --adjust option applies drift correction factors stored in /etc/adjtime, compensating for systematic inaccuracies in the hardware clock's timekeeping. 5. Diagnostic Features: Options like --debug provide detailed information about hwclock operations, useful for troubleshooting time synchronization issues. 6. Manual Time Setting: The --set option along with --date allows manually setting the hardware clock to a specific time, which is useful when bootstrapping a new system or correcting significant time discrepancies. 7. Administration Privileges: Most hwclock operations require root privileges since they involve direct hardware access and can affect system-wide time settings. Hwclock is particularly important in systems that don't have continuous network access to time servers (like those using NTP or systemd-timesyncd). It helps maintain reasonably accurate time between boots and during periods without network connectivity. However, in always-connected systems, the hardware clock typically serves as a fallback, with network time synchronization providing more precise timekeeping during operation. In modern Linux distributions using systemd, some of hwclock's functionality is also available through the timedatectl command, which provides a more integrated approach to time management.

    Related Commands

    These commands are frequently used alongside hwclock or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the hwclock command works in different scenarios.

    $ hwclock
    View All Commands