For social, commercial, and legal purposes, areas on the world map that share a uniform standard time complete the definition of a time zone. Therefore, the implementation of a time zone depends on the divisions and boundaries that separate different countries and regions.
This approach of identifying time zones is more convenient than strictly relying on longitudes. Enough with the geography lesson, let us get back to solving computing problems the Linux way.
Linux is smart enough to identify the time zone you are under; whether you are a Linux developer on the move or a Linux enthusiast that embraces a change in their environment from time to time.
Under the Linux operating system environment, you will never fail to come across time management utilities like date and timedatectl. It is through such time management utilities that we can be able to run various Linux command tweaks to reveal the exact current system time zone associated with our environment.
How to Find Linux System Timezone
To successfully retrieve the current system time zone of our Linux system, we will use several inbuilt Linux command implementations:
Method 1: Using timedatectl Command
According to its man page, the timedatectl command is primarily used to manipulate the Linux system’s time and date values. Executing the command should additionally retrieve time and date-related values like Local time, Universal time, RTC time, System clock synchronized status, NTP service state, and RTC in local TZ value entry.
$ timedatectl
As per the above time zone, we are currently in Africa/Nairobi (EAT, +0300).
As you might have noticed from the execution of the timedatectl command as demonstrated above, we are forced to filter through unwanted output values to single out the Time Zone value we are after.
What if we wanted to only output the Time Zone value from the timedatectl command? It is at this point that we borrow the efficiency of the grep command, which will primarily single out the entry associated with the Time Zone from the timedatectl command as demonstrated below:
$ timedatectl | grep 'Time zone'
Method 2: Using date Command
As per the man page of date command, it primarily serves the purpose of printing or setting the date and time values on your Linux operating system. A segment of its execution results should point us to the time zone our system is using.
$ date
As expected, the command execution has pointed us to the correct time zone.
Method 3: Using cat Command
According to its manual page, the cat command primarily prints out the standard output associated with a concatenated file. The /etc Linux OS directory contains a file called timezone. Printing the content of this file via the cat command should reveal to us the current system time zone.
$ cat /etc/timezone
We are now confident in our ability to get the current time zone in Linux from the command-line environment.