How to change the timezone in Linux?

Timezone

In this tutorial, we will discuss how to change the timezone in Linux. There are two ways to set the timezone in Linux:

  • Through CLI
  • Through GUI

Let’s discuss how to set the timezone through CLI

Set timezone through CLI

There are simple steps through which we can set the timezone. First, we should know how to check the time in Ubuntu through CLI.

To check the timezone using the command in Ubuntu

We can use the following command to check the time in Ubuntu:

# timedatectl
Datectl Step1
Check time using the command

It will print the current timezone of your system.

To check the current timezone using ls command

There is also an alternative command to check the timezone using ls command if somewhat the above command fails.

The command is as follows:

# ls -l /etc/localtime
Localtime Step2
An alternative way to check the timezone

If you only want to print the timezone like UTC or GMT, You can also do the following:

# cat /etc/timezone
Timezone Through Cat Step3
Timezone using cat command

List all the available timezones

Now, what if you want to print the list of the available timezones. For this just add “list-timezones” with “timedatectl” command.

The syntax for this is as follows:

# timedatectl list-timezones
Timezone List Step4
List of available timezones

The timedatectl is using /usr/share/zoneinfo/ directory to generate the timezone list.

Print the timezone of the particular zone

The above command will print all the available timezones. But what if you want to print the timezone of only Asian countries or of Europe. For this, we need to combine the time command with grep command. Let’s look at the example below:

# timedatectl list-timezones | grep -i "asia"
Search Through Patter Example2
Print the timezone of the particular zone

Look at another example given below:

# timedatectl list-timezones | grep -i "India"
Search Throug Pattern Step6
Print the timezone of the particular zone

Here I have used the grep command to search for the particular word. ‘|’ symbol is used to combine two commands. I hope its cleared.

How to Change Timezone in Linux?

As of now, we are cleared that how to check the current timezone. Let’s understand how to change the timezone. This can be done using the following command:

# sudo timedatectl set-timezone Europe/Paris 
Timezone Change Example1 1
Change the timezone- example 1

Let’s understand again from this example:

# sudo timedatectl set-timezone Africa/Monrovia
Timezone Change Example2
Change the timezone – example 2

Confirm the timezone using timezonectl command as shown above.

Change the Timezone in Linux Using tzdata Command

There is another way to change the timezone in Linux using tzdata. Let’s understand by the following example:

First, you need to figure out the timezone you want to configure. Next, save the timezone using the following command in /etc/timezone.

# echo "Europe/Paris" | sudo tee /etc/timezone
Echo Timezone Step 5
Save the timezone

Here, we have used tee command which is used to capture the intermediate output and writes it content to standard output. Use the following command to change the timezone:

# sudo dpkg-reconfigure --frontend noninteractive tzdata
Dpkg Timezone Step7
Change the timezone

It will print the current timezone. I hope it’s clear.

Change the timezone in Ubuntu using GUI

Earlier we discussed how to change the timezone in Linux using CLI. Let’s understand how to change the timezone using GUI in Ubuntu.

1. Open the settings

Select the settings either by clicking on activities or by direct shortcut as shown in the figure below:

GUI Step 1
Open the settings

2. Select Date and Time Tab

A new window will open where you need to select the date and time tab. Further, turn the Automatic Time Zone to off and on the Time zone box to change the timezone as shown in the figure given below:

GUI Select Date And Time
Select the Timezone

3. Set the timezone

On clicking the timezone box option, it will be redirected to a new window as shown in the figure given below:

GUI Set Timezone Step3
Set the Timezone

Here, you need to set the timezone.

Conclusion

That’s it. You can now set the timezone using wither GUI or CLI as described in the above steps. If facing any issue then do let us know in the comment section. If you need to check details about any of the commands discussed in this tutorial, go ahead and use the man command in Linux to learn more about the commands.