Sometime you need to update your system timezone when you move your server from one location to another location. Recently our one user came across a situation where he want to move their server time zone from IST to Sydney time zone and he requested me to post a article on this topic that’s why through this article I will explain how to set system timezone of your Linux/Unix machine.
Update Time Zone In Linux/Unix
First check what is your system time zone typing below command:
# date Mon Sep 11 10:18:49 IST 2017
In Linux timezone date command is taken from /etc/localtime file, this file is linked to one on of the file located in /usr/share/zoneinfo/* . So first you have to remove the file and then link this to new file, for example in my case I want to set my time zone as Sydney, that’s why I have to link my /etc/localtime file with Sydeny file as shown below.
# ls -l /etc/localtime -rw-r--r-- 1 root root 2194 Jun 6 2008 /etc/localtime # unlink /etc/localtime
Now check where is Sydney file located in /usr/share/zoneinfo/ folder.
# ls /usr/share/zoneinfo/ Africa Chile GB Indian MST PRC UTC America CST6CDT GB-Eire Iran MST7MDT PST8PDT WET Antarctica Cuba GMT iso3166.tab Navajo right W-SU Arctic EET GMT0 Israel NZ ROC zone.tab Asia Egypt GMT-0 Jamaica NZ-CHAT ROK Zulu Atlantic Eire GMT+0 Japan Pacific Singapore Australia EST Greenwich Kwajalein Poland Turkey Brazil EST5EDT Hongkong Libya Portugal UCT Canada Etc HST MET posix Universal CET Europe Iceland Mexico posixrules US # ls /usr/share/zoneinfo/Australia/ ACT Canberra Hobart Melbourne Queensland Victoria Adelaide Currie LHI North South West Brisbane Darwin Lindeman NSW Sydney Yancowinna Broken_Hill Eucla Lord_Howe Perth Tasmania
After finding Sydney file now link it to our /etc/localtime file like below:
# ln -s /usr/share/zoneinfo/Australia/Sydney /etc/localtime
Once above command executed successfully now check if date is update with new timezone.
# date Mon Sep 11 10:30:49 EST 2017