ntpdate

systemLinux/Unix
The ntpdate command is one of the most frequently used commands in Linux/Unix-like operating systems. ntpdate Set the system date and time via NTP

Quick Reference

Command Name:

ntpdate

Category:

system

Platform:

Linux/Unix

Basic Usage:

ntpdate [options] [arguments]

Common Use Cases

    Syntax

    ntpdate [options] server [server...]

    Options

    Option Description
    -a Enable authentication using keys and key IDs
    -b Step time regardless of the difference
    -B Force the time to always step instead of slew
    -d Enable debugging output
    -e AUTHDELAY Specify the authentication processing delay in seconds
    -k KEYFILE Specify the path to the file containing authentication keys
    -K KEYID Specify the key ID to use for authentication
    -o VERSION Specify the NTP version to use (1-4, default: 4)
    -p SAMPLES Specify the number of samples to acquire from each server (default: 1)
    -q Query only - don't set the clock
    -s Log to the system log facility instead of standard output
    -t TIMEOUT Specify the time to wait for a response in seconds (default: 1)
    -u Use an unprivileged port for outgoing packets
    -v Be verbose and show statistics about time adjustment

    Examples

    How to Use These Examples

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

    # Basic Examples Basic
    ntpdate time.nist.gov
    Set the system time using the NIST time server.
    sudo ntpdate pool.ntp.org
    Synchronize system time with NTP pool servers (requires root privileges).
    # Advanced Examples Advanced
    ntpdate -q time.google.com Query the time server without adjusting the local clock. ntpdate -d pool.ntp.org Enable debugging output for detailed information about the time synchronization process. ntpdate -u time.apple.com Use unprivileged port for outgoing packets (useful when running behind a firewall). ntpdate -b ntp.ubuntu.com Step the time (make immediate time correction regardless of the difference). ntpdate -s pool.ntp.org Log output to the system log facility instead of standard output. ntpdate -t 5 time.windows.com Set the timeout to 5 seconds (default is usually 1 second). ntpdate -p 8 0.pool.ntp.org 1.pool.ntp.org Use 8 samples from each server for better accuracy and query two servers. sudo ntpdate -B time.cloudflare.com Force the time to always step instead of slew, even for small time differences.

    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 ntpdate command is a utility for synchronizing the system clock with Network Time Protocol (NTP) servers. Originally part of the NTP software suite, ntpdate allows administrators to quickly set the local system time from one or more remote time servers. It's particularly useful for making immediate, one-time adjustments to the system clock. While ntpdate is still widely available and used, it's worth noting that in many modern Linux distributions, it's considered somewhat deprecated in favor of the ntpd daemon (when run with the -q option) or the newer chronyd service, which provides more continuous and accurate timekeeping. However, ntpdate remains valuable for specific use cases, especially for scripts and situations requiring quick, one-time synchronization. Key features of the ntpdate command: 1. Quick Synchronization: ntpdate provides immediate time synchronization without the need to run a continuous time synchronization daemon. 2. Multiple Server Support: It can query multiple time servers and select the best one based on factors like response time and estimated time accuracy. 3. Adjustment Methods: ntpdate can either "step" the time (make immediate, potentially large adjustments) or "slew" it (make gradual adjustments) depending on the options used and the size of the time difference. 4. Authentication: It supports authenticated NTP for environments where security is a concern. 5. Diagnostic Capabilities: The query-only mode allows checking time differences without making changes, useful for monitoring and diagnostics. Common use cases for ntpdate include: - Initial time synchronization during system boot, before starting a continuous NTP service - One-time correction of system time on machines without running NTP daemons - Scripted time synchronization for systems that aren't continuously connected to the network - Troubleshooting time synchronization issues by querying time servers - Testing the availability and response of NTP servers When using ntpdate, it's important to be aware that making large time adjustments can potentially affect running applications, especially those that depend on consistent time progression. For servers and critical systems, a continuously running NTP daemon (ntpd or chronyd) is generally preferred for maintaining accurate time. For security reasons, ntpdate typically requires root privileges to modify the system time. The -u option can be used to work around certain firewall restrictions by using unprivileged ports for outgoing packets. Many organizations and public entities maintain NTP servers that can be used with ntpdate, including the NTP Pool Project (pool.ntp.org), which provides a distributed network of volunteer NTP servers, as well as technology companies like Google, Apple, and Microsoft.

    Related Commands

    These commands are frequently used alongside ntpdate 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 ntpdate command works in different scenarios.

    $ ntpdate
    View All Commands