timedatectl Linux Command | Explained

In Linux, the timedatectl command displays and modifies the current time and date. The “timedatectl” command shows the status that contains the  “Universal time”, “Local time”, and the “Real Time Clock” time. Moreover, it can also be used to display or set the current timezone of the system. Considering the importance of the timedatectl command, this post will provide a deep insight into the timedatectl command with all of its functionalities.

Let’s get started!

What is the timedatectl Command in Linux?

In Linux, the “timedatectl” command represents the current date and time of the system. Its working depends on the following syntax:

Syntax:

The basic syntax of the “timedatectl” command is written below:

$ timedatectl [Options] [Command]
How to install Kali Linux in Window...

In the syntax, the square brackets show the supported options of the “timedatectl” command, which are described in the following table:

timedatectl – OptionsDescription
–versionShows the short system version string.
–no-pagerDisplays the output in one-page means do not convey output via pager.
-h, –helpProvides the brief information of the “timedatectl” command.
–no-ask-passwordDo not ask the user for the password.
-H, –host=It assists the system operations in remote manners
-M, –machine=It is used to run the operations in a local container. The container connects to the user name separated by the “@” character.
-a, –allUsed to show all the properties whether these are set or not.

These options and the basic working of the timedatectl command can be viewed via the following command:

$ timedatectl --help

Let’s explore the use cases of this command.

How to Use timedatectl Command in Linux?

As discussed earlier, the purpose of this command is to manage the time, date, and timezone settings on your Linux system. For a better understanding, this section offers numerous examples that show the practical usage of this command:

Example 1: How to Check the System Clock Status?

The “timedatectl status” can be used to check the current status of the system clock and the synchronization status, whether it is enabled or disabled.

$ timedatectl status

The output contains the following components:

  • Local Time: It displays the date and local time using EST(Eastern Standard Time).
  • Universal Time: It shows the Universal time using the UTC timezone.
  • RTC Time: Real-Time Clock is a “Hardware clock” that keeps the date/time up to date even the system is turned off.
  • Time zone: It represents the current system timezone.
  • System clock synchronized”: The “system clock synchronized ” system verifies whether all the system clocks are synchronized.
  • NTP services: The “NTP” (Network Time Protocol) allows the user to synchronize all the system clocks within the network.
  • RTC in local TZ: It shows that the current Linux system uses the local timezone.

Example 2: How to Inspect the System Clock Status?

The “timedatectl show” command conveys the same information in human-readable format:

$ timedatectl show

Example 3: How to Check the List of Available Timezones?

Type the “timedatectl list-timezones” command on the terminal to know about the timezone list supported by your installed Linux operating system:

$ timedatectl list-timezones

Example 4: How to Change the Local Timezone?

The “timedatectl set-timezone” command allows the users to change the Local timezone supported by the current Linux system. For instance, the command below has set the current timezone to “America/Bahia”. Lastly, the “timedatectl” command is executed to verify the timezone:

$ timedatectl set-timezones "America/Bahia"

Example 5: How to Modify the Current Time and Date?

The “timedatectl set-time” command helps change the date and time of the particular Linux system. The date is set in the “Year-Month-Day” format while the time follows the “Hour:Minutes: Seconds” format:

$ timedatectl set-time  "yyyy-mm-dd HH:MM:SS"

After executing the command, an error occurred that shows the automatic time synchronization status, i.e. “enabled”.

To sort out this error, type the following command on the terminal:

$ sudo systemctl stop systemd-timesyncd.service

Next, enter the root user password and type the same “timedatectl set-time” command again. You will get an error-free output, and the time/date has been changed:

The output represents the new date and time modified by the user.

Example 6: How to Synchronize the RTC With Local/Universal Time?

The “timedatectl” command is beneficial to synchronize the local timezone and universal timezone with RTC (Real Time Clock) or the “Hardware clock ”.

Sync RTC WIth UTC

To sync the RTC with the UTC (Universal Time Clock), pass the binary digit “0” and run the following command:

$ timedatectl set-local-rtc 0

Using the timedatectl command, as shown above, it is observed that RTC is not in local TZ (therefore, it is concluded that RTC is in UTC at the moment).

Sync RTC With Local TZ

To synchronize the RTC with the local time zone, pass the binary digit “1” and execute the command:

$ timedatectl set-local-rtc 1

The output can be verified by using the timedatectl command as shown above that RTC is in local TZ.

Example 7: How to Activate/Deactivate the NTP Protocol?

The “timedatectl” command is also useful to activate or deactivate the “Network Time Protocol”. The system clock can be integrated with a remote server by utilizing the “NTP” protocol. The NTP server synchronizes its time by contacting several servers around the world.

Enable NTP Support

To enable the “NTP”, run the following command:

$ timedatectl set-ntp true

The command shows some problems as the RTC is synchronized with Local TZ. To avoid this, your RTC must be in UTC.

Disable NTP

Similarly, disable the “NTP” synchronization by executing the command:

$ timedatectl set-ntp false

That’s all about this detailed tutorial of the timedatectl command.

Conclusion

The “timedatectl” command is useful for displaying information related to time, date, and timezone. It is also beneficial to set the date/time and time zone. This utility provides information like “Local time”, “Universal time”,RTC time”, “NTP services, and “RTC in local TZ”. Furthermore, the “timedatectl” command contains a list of commands and options having different functionalities. This post has briefly illustrated the timedatectl command working and usage in Linux.