Saturday, March 18, 2017

Change time zone in Linux

Red Hat distros

If you're using a distribution such as Red Hat then your approach of copying the file would be mostly acceptable.
$ ls /usr/share/zoneinfo/
Africa/      CET          Etc/         Hongkong     Kwajalein    Pacific/     ROK          zone.tab
America/     Chile/       Europe/      HST          Libya        Poland       Singapore    Zulu
Antarctica/  CST6CDT      GB           Iceland      MET          Portugal     Turkey       
Arctic/      Cuba         GB-Eire      Indian/      Mexico/      posix/       UCT          
Asia/        EET          GMT          Iran         MST          posixrules   Universal    
Atlantic/    Egypt        GMT0         iso3166.tab  MST7MDT      PRC          US/          
Australia/   Eire         GMT-0        Israel       Navajo       PST8PDT      UTC          
Brazil/      EST          GMT+0        Jamaica      NZ           right/       WET          
Canada/      EST5EDT      Greenwich    Japan        NZ-CHAT      ROC          W-SU         
I would recommend linking to it rather than copying however.
$ sudo unlink /etc/localtime 
$ sudo ln -s /usr/share/zoneinfo/Etc/GMT+6 /etc/localtime
Now date shows the different timezone:
$ date -u
Thu Jan 23 05:40:31 UTC 2017

$ date 
Wed Jan 22 23:40:38 GMT+6 2017

Ubuntu/Debian Distros

To change the timezone on either of these distros you can use this command:
$ sudo dpkg-reconfigure tzdata
    ss #1
$ sudo dpkg-reconfigure tzdata

Current default time zone: 'Etc/GMT-6'
Local time is now:      Thu Jan 23 11:52:16 GMT-6 2017.
Universal Time is now:  Thu Jan 23 05:52:16 UTC 2017.
Now when we check it out:
$ date -u
Thu Jan 23 05:53:32 UTC 2017

$ date 
Thu Jan 23 11:53:33 GMT-6 2017
NOTE: There's also this option in Ubuntu 14.04 and higher with a single command (source: Ask Ubuntu - setting timezone from terminal):

$ sudo timedatectl set-timezone Etc/GMT-6