adjtime - Linux
Overview
adjtime is a Linux command that allows users to modify and retrieve the system’s time and date. It provides precise control over the kernel’s timekeeping mechanisms, making it useful for fine-tuning accuracy or synchronizing with external time sources.
Syntax
adjtime [-k | -s] [offset]
Options/Flags
- -k: Read and display the current time offset.
- -s [offset]: Modify the current time offset. The offset is specified in milliseconds and can be either positive or negative.
Examples
- Retrieve the current time offset:
adjtime -k
- Adjust the time by 100 milliseconds:
adjtime -s 100
- Set the time offset to -200 milliseconds:
adjtime -s -200
Common Issues
- Insufficient privileges: You must have root privileges to use adjtime.
- Invalid offset: The offset must be within a reasonable range (typically ±1000 milliseconds).
- Time drift: Setting the time offset can cause time drift, so it should be used sparingly.
Integration
adjtime can be integrated into scripts or cron jobs for automated time adjustments. For example, to sync with an external NTP server every hour:
0 */1 * * * /usr/sbin/adjtime -s "$(ntpdate -q -b)"
Related Commands
- ntpdate: Synchronizes the system clock with an NTP server.
- hwclock: Modifies and retrieves the hardware clock.
- date: Displays and sets the system date and time.