How to check if a timezone is set in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the timezone setting on a Linux system. We will explore different methods to verify the configured timezone, which is crucial for accurate timekeeping and system operations.

You will begin by using the timedatectl command to get a comprehensive overview of the system's time and date settings, including the active timezone. Following that, you will inspect the /etc/timezone file using the cat command to see where the timezone information is typically stored on Debian-based systems. Finally, you will examine the /etc/localtime file using ls -l to understand how the system links to the specific timezone data.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/SystemInformationandMonitoringGroup -.-> linux/date("Date/Time Displaying") subgraph Lab Skills linux/ls -.-> lab-558772{{"How to check if a timezone is set in Linux"}} linux/cat -.-> lab-558772{{"How to check if a timezone is set in Linux"}} linux/date -.-> lab-558772{{"How to check if a timezone is set in Linux"}} end

Check timezone with timedatectl

In this step, we will learn how to check the system's timezone using the timedatectl command. Understanding the system's timezone is important for scheduling tasks, logging, and ensuring accurate timestamps.

The timedatectl command is a utility that controls the system time and date. It can be used to query and change the system clock, its synchronization with a remote NTP server, and the system's timezone.

Open your terminal if it's not already open. You can find the Xfce Terminal icon on the left side of your desktop.

Now, type the following command and press Enter:

timedatectl

You should see output similar to this:

               Local time: ...
           Universal time: ...
                 RTC time: ...
                Time zone: ... (... ...)
System clock synchronized: ...
              NTP service: ...
          RTC in local TZ: ...

Look for the line that starts with Time zone:. This line shows the current timezone configured on the system. For example, it might show Time zone: Etc/UTC (UTC, +0000).

This command gives you a comprehensive overview of the system's time and date settings, including the active timezone.

Click Continue to proceed to the next step.

Verify timezone file with cat /etc/timezone

In the previous step, we used timedatectl to see the timezone. Now, let's look at where this information is often stored on Debian-based systems like Ubuntu.

The system's timezone is typically configured in the /etc/timezone file. We can use the cat command to display the contents of this file. The cat command is a simple utility used to display the content of files.

Type the following command in your terminal and press Enter:

cat /etc/timezone

You should see the timezone name printed to the terminal, for example:

Etc/UTC

This file contains the timezone name in a format that the system understands. This is a quick way to verify the configured timezone without using timedatectl.

Understanding where configuration files are located is a key part of navigating and managing a Linux system. The /etc directory is a standard location for system configuration files.

Click Continue to move on to the next step.

Inspect localtime with ls -l /etc/localtime

In addition to the /etc/timezone file, Linux systems often use a symbolic link at /etc/localtime to point to the actual timezone data file. This symbolic link tells the system which timezone rules to use.

A symbolic link (or symlink) is a special type of file that points to another file or directory. It's like a shortcut.

We can use the ls -l command to inspect this symbolic link. The ls command lists directory contents, and the -l option provides a long listing format, showing details like permissions, ownership, size, and where a symbolic link points.

Type the following command in your terminal and press Enter:

ls -l /etc/localtime

You should see output similar to this:

lrwxrwxrwx 1 root root ... /etc/localtime -> ../usr/share/zoneinfo/Etc/UTC

Look at the end of the output. The -> symbol indicates that /etc/localtime is a symbolic link, and it points to /usr/share/zoneinfo/Etc/UTC. This path /usr/share/zoneinfo/ contains the actual timezone data files for various regions and cities.

This confirms that the system's time is being interpreted according to the rules defined in the linked timezone data file.

You have now learned three different ways to check the timezone on a Linux system: using timedatectl, viewing /etc/timezone, and inspecting the /etc/localtime symbolic link.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check the system's timezone in Linux using two primary methods. First, we utilized the timedatectl command, a comprehensive utility for managing system time and date settings, to view the current timezone along with other relevant information like local and universal time. This command provides a detailed overview of the system's time configuration.

Secondly, we explored the /etc/timezone file, which on Debian-based systems like Ubuntu, typically stores the system's timezone name. By using the cat command to display the contents of this file, we were able to quickly verify the configured timezone name, offering a direct way to access this specific setting.