CentOS / RHEL 5,6 : How to Change the timezone

Timezone configuration on Linux is usually set up at installation time. On RHEL 5 and 6, the procedure to change the Timezone configuration is as follows. The example used here is from timezone MDT to IST. The timezone can be either changed from command line or using the system-config-date command.

Using system-config-date command

Use the system-config-date graphical utility:

# system-config-date

In case the command is not available, install the required package with yum :

# yum install system-config-date

Use the system-config-date graphical tool to set the required timezone from a list of timezones as shown below.

Using the command line

1. Check the file /etc/sysconfig/clock and the date command output to confirm the current timezone set.

# cat /etc/sysconfig/clock
ZONE="America/Denver"
# date
Wed May 17 13:41:16 MDT 2017

2. Navigate to the directory /usr/share/zoneinfo and check the available files. (Each file represents a timezone). Find the file representing the timezone to be configured.

# cd /usr/share/zoneinfo
[root@VOM-VCS-MONITOR zoneinfo]# ls -l
total 296
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Africa
drwxr-xr-x.  6 root root  4096 Aug 15  2014 America
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Antarctica
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Arctic
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Asia
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Atlantic
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Australia
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Brazil
drwxr-xr-x.  2 root root  4096 Aug 15  2014 Canada
......

3. Replace the value on /etc/sysconfig/clock with the path to that file starting from /usr/share/zoneinfo. For example, if the target timezone is IST time for India. The file under /usr/share/zoneinfo representing that timezone is:

/etc/share/zoneinfo/Asia/Kolkata

Therefore, change /etc/sysconfig/clock file so it reads:

ZONE="Asia/Kolkata"

4. Replace /etc/localtime with the appropriate zone file by reading /etc/sysconfig/clock using this command:

# tzdata-update
Replacing /etc/localtime with symlinks to a zone file in RHEL 5 and RHEL 6 is Unsupported.

Verify

You can verify the change of timezone by “date” command and checking the /etc/sysconfig/clock file as shown below.

# cat /etc/sysconfig/clock
ZONE="Asia/Kolkata"
# date
Wed May 17 15:30:22 IST 2017

CentOS / RHEL : Using yum to download a package without installing it

Configuring a different timezone for individual users

To configure a different time zone from the system-wide default for an individual user, add the following line to the .bashrc in that user’s home directory:

export TZ="/usr/share/zoneinfo/[timezone_directory]/[timezone_file]"

In the above directive, replace [timezone_directory] with a time zone directory in the /usr/share/zoneinfo/ directory, such as US, and replace [timezone_file] with a time zone file within that time zone directory, such as Eastern. It is possible to reference any file within the /usr/share/zoneinfo/ directory for valid values.

Related Post