How to update time zone in Linux?
Some times it is required to update our timezone when we move our machines(VMs) from one location to other. Recently I came across a situation where I want to move my machine time zone from IST to Sydney time zone. In this post we will see on how to set time zone in a Linux machine.
Check which time zone you are in by executing date command.
[root@node1 ssl]# date
Fri Nov 21 03:18:49 IST 2014
In Linux timezone data is taken from /etc/localtime which is linked to one of the file located in /usr/share/zoneinfo/*. So we have to first remove this file and then link this file to one of the timezone files located in /usr/share/zoneinfo folder. As my requirement is to set my time zone as Sydney, I will link my /etc/localtime with Sydney file as shown below.
Step1: Remove /etc/localtime
[root@node1 ssl]# ls -l /etc/localtime
-rw-r--r--. 3 root root 265 Nov 12 2010 /etc/localtime
[root@node1 ssl]# unlink /etc/localtime
Step2: Now check where is Sydney related file located in /usr/share/zoneinfo folder.
[root@node1 ssl]# ls -l /usr/share/zoneinfo/
Africa/ Atlantic/ Chile/ Eire Factory GMT-0 Iceland Jamaica Mexico/ NZ posix/ ROC Universal zone.tab
America/ Australia/ CST6CDT EST GB GMT+0 Indian/ Japan Mideast/ NZ-CHAT posixrules ROK US/ Zulu
Antarctica/ Brazil/ Cuba EST5EDT GB-Eire Greenwich Iran Kwajalein MST Pacific/ PRC Singapore UTC
Arctic/ Canada/ EET Etc/ GMT Hongkong iso3166.tab Libya MST7MDT Poland PST8PDT Turkey WET
Asia/ CET Egypt Europe/ GMT0 HST Israel MET Navajo Portugal right/ UCT W-SU
[root@node1 ssl]# ls -l /usr/share/zoneinfo/Australia/
ACT Brisbane Canberra Darwin Hobart Lindeman Melbourne NSW Queensland Sydney Victoria Yancowinna
Adelaide Broken_Hill Currie Eucla LHI Lord_Howe North Perth South Tasmania West
Step3: Once you find Sydney file just link to our /etc/localtime file as shown below
[root@node1 ssl]# ln -s /usr/share/zoneinfo/Australia/Sydney /etc/localtime
Step4: Once the above step is done successfully try check if date is update with right timezone or not
[root@node1 ssl]# date
Fri Nov 21 08:53:03 EST 2014
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix- June 29, 2020
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018