In Linux, the system time zone is determined by the symbolic link /etc/localtime. This symbolic link points to a time zone data file located at either /usr/share/zoneinfo or /usr/lib/zoneinfo depending on Linux distribution. So changing the system timezone is just a simple job of updating this symbolic link.
Run the following command to view the list of regions
ls -l /usr/share/zoneinfo
Choose the most appropriate region.
Suppose we have to set the system timezone as UK timezone, so we pick up “Europe” as the region. “Europe” is a directory in /usr/share/zoneinfo.
Now run following ls command to view the city listing and choose an appropriate one.
ls -l /usr/share/zoneinfo/Europe
We choose London for our example.
Next step is to update the symbolic link, so run the following command
ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
If you wish you could have taken a backup before updating the symbolic link as below
mv /etc/localtime /etc/localtime-bck
In CentOS, you might need to also edit /etc/sysconfig/clock. This file contains an entry as shown below
ZONE="Europe/London"
Now verify whether timezone has been updated or not by running the date command.
[wbs@DVSRVR001 ~]$ date Mon Jul 14 18:21:40 BST 2014 [wbs@DVSRVR001 ~]$
BST stands for “British Summer Time”.
To change the timezone for the current user session only, you can set the environment variable TZ as shown below
export TZ="Europe/London"
One more method of changing the system timezone is to run one of the following commands based on your Linux distribution you may.
Ubuntu: dpkg-reconfigure tzdata
Redhat: redhat-config-date
CentOS/Fedora: system-config-date
FreeBSD/Slackware: tzselect
This method will open an ASCII menu that will allow you to choose your timezone. Current timezone is selected by default when the menu opens.
Running the command “dpkg-reconfigure tzdata
” in Ubuntu displays the screen shown in the image below
Leave a Comment