Use Timedatectl to Manage Time, Date, more Linux Commands
Managing Time, Date, and Timezone with Timedatectl
Managing the time, date, and timezone on a Linux system is crucial for maintaining the timely operation of system tasks, accurate logging, and synchronization with other systems. The timedatectl
command, part of the systemd
system and service manager, is a powerful tool for querying and changing these settings.
Displaying Current Time and Date Settings
To view the current time and date settings on your Linux system, you can use the timedatectl
command without any arguments. This command will display detailed information about the system clock, including local time, universal time, RTC (Real-Time Clock) time, and the currently used timezone.
$ timedatectl
Local time: Thu 16:12:31 EST
Universal time: Thu 16:12:31 UTC
RTC time: Thu 16:12:31
Listing Available Timezones
If you need to change the timezone, you first need to identify the available timezones. You can list all available timezones using the following command:
$ timedatectl list-timezones
This command will output a comprehensive list of timezones. To narrow down the list, you can use grep
to search for specific regions or cities.
$ timedatectl list-timezones | grep EST
Setting the Timezone
To set a new timezone, use the set-timezone
option followed by the desired timezone. For example, to set the timezone to "Asia/Kolkata":
$ timedatectl set-timezone "Asia/Kolkata"
It is recommended to use the coordinated universal time (UTC) for consistency across different systems.
$ timedatectl set-timezone UTC
Setting the Date and Time
You can manually set the date and time using the set-time
option. To set only the time, use the format HH:MM:SS
:
$ timedatectl set-time 15:58:30
If you encounter an error indicating that the NTP service is active, you need to disable it before setting the time manually:
$ systemctl disable --now chronyd
$ timedatectl set-ntp false
$ timedatectl set-time 15:58:30
To set both the date and time, use the format YYYY-MM-DD HH:MM:SS
:
$ timedatectl set-time '2023-06-02 14:05:00'
Enabling Network Time Synchronization
To ensure your system clock remains accurate, you can enable network time synchronization using the set-ntp
option:
$ timedatectl set-ntp true
This command will activate the systemd-timesyncd
service, which synchronizes the system clock with a remote NTP server.
Additional Commands and Options
-
Displaying Time Synchronization Status: To check the status of time synchronization services, use:
$ timedatectl timesync-status
-
RTC Time: To check the hardware clock (RTC) time, you can see it in the output of the
timedatectl
command without arguments. -
Daylight Saving Time (DST): The
timedatectl
command also displays information about DST, including whether it is active and when the next change will occur.
By using these commands and options, you can effectively manage the time, date, and timezone settings on your Linux system, ensuring that your system operates accurately and in sync with other systems.