How to use the command 'timedatectl' (with examples)

How to use the command 'timedatectl' (with examples)

Timedatectl is a command-line tool in Linux that allows users to control and manage the system time and date. It provides several functionalities such as checking the current system clock time, setting the local time of the system clock, listing available timezones, setting the system timezone, enabling Network Time Protocol (NTP) synchronization, and changing the hardware clock time standard to localtime.

Use case 1: Check the current system clock time

Code:

timedatectl

Motivation: By checking the current system clock time, users can ensure that their system’s clock is accurate and in sync with the correct time. This is important to avoid any issues related to time discrepancies when using applications or services that rely on accurate time information.

Explanation: The command timedatectl without any arguments fetches and displays the current system clock time and other relevant time and date information. It provides details such as the current time, time zone, whether the system clock is synchronized or not, etc.

Example output:

               Local time: Sat 2021-09-18 10:30:45 UTC
           Universal time: Sat 2021-09-18 10:30:45 UTC
                 RTC time: Sat 2021-09-18 10:30:45
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Use case 2: Set the local time of the system clock directly

Code:

timedatectl set-time "yyyy-MM-dd hh:mm:ss"

Motivation: Setting the local time of the system clock directly can be useful when the system time needs to be adjusted manually due to incorrect synchronization or other reasons. It allows users to precisely set the desired time without relying on automated time synchronization mechanisms.

Explanation: The command timedatectl set-time "yyyy-MM-dd hh:mm:ss" sets the local time of the system clock to the specified date and time. Users need to replace yyyy-MM-dd with the desired date in the format Year-Month-Day, and hh:mm:ss with the desired time in the format Hour:Minute:Second.

Example output: None. Upon successful execution, the system clock time will be changed, but there will be no immediate command output.

Use case 3: List available timezones

Code:

timedatectl list-timezones

Motivation: Listing available timezones allows users to choose the appropriate timezone for their system based on their geographical location or specific requirements. It helps in accurately representing local time and managing time adjustments such as Daylight Saving Time (DST).

Explanation: The command timedatectl list-timezones displays a long list of available timezones supported by the system. This includes various cities, regions, and countries that can be used to set the system timezone.

Example output:

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
...

Use case 4: Set the system timezone

Code:

timedatectl set-timezone timezone

Motivation: Setting the system timezone is essential to ensure that the system’s clock accurately represents the local time of the user’s location. It helps in keeping the timestamp information consistent and facilitates correct time-related operations.

Explanation: The command timedatectl set-timezone timezone sets the system timezone to the specified timezone. Users need to replace timezone with the desired timezone from the list of available timezones obtained using the timedatectl list-timezones command.

Example output: None. Upon successful execution, the system timezone will be changed, but there will be no immediate command output.

Use case 5: Enable Network Time Protocol (NTP) synchronization

Code:

timedatectl set-ntp on

Motivation: Enabling Network Time Protocol (NTP) synchronization allows the system clock to automatically synchronize with time servers on the internet. This ensures that the system time remains accurate and is constantly adjusted to the correct time.

Explanation: The command timedatectl set-ntp on enables NTP synchronization on the system. It configures the system to periodically synchronize its clock with designated NTP servers on the internet.

Example output: None. Upon successful execution, NTP synchronization will be enabled, but there will be no immediate command output.

Use case 6: Change the hardware clock time standard to localtime

Code:

timedatectl set-local-rtc 1

Motivation: Changing the hardware clock time standard to localtime can be necessary if the system’s hardware clock is configured to use Universal Coordinated Time (UTC) by default. In some cases, it may be desired to switch to the localtime standard to match the system’s timezone settings.

Explanation: The command timedatectl set-local-rtc 1 changes the hardware clock time standard to localtime. By default, Linux systems use UTC for the hardware clock. Setting the value to 1 switches to the localtime standard.

Example output: None. Upon successful execution, the hardware clock time standard will be changed, but there will be no immediate command output.

Conclusion:

The timedatectl command provides a convenient way to control and manage the system time and date in a Linux environment. It offers various functionalities such as checking the current system clock time, setting the local time of the system clock, listing available timezones, setting the system timezone, enabling NTP synchronization, and changing the hardware clock time standard. By utilizing these capabilities, users can ensure accurate timekeeping and align the system’s time with their specific requirements.

Related Posts

Using the `yetris` command (with examples)

Using the `yetris` command (with examples)

Tetris is a classic puzzle game that has been enjoyed by millions of players worldwide.

Read More
How to use the command speedtest-cli (with examples)

How to use the command speedtest-cli (with examples)

Speedtest-cli is a command-line tool used to test internet bandwidth by connecting to speedtest.

Read More
How to use the command `nvm` (with examples)

How to use the command `nvm` (with examples)

The nvm command is a tool that allows you to easily manage different versions of Node.

Read More