Pages

Monday, 30 July 2012

How to set the time zone in Linux



How to set the time zone on as per user basis in RHEL

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>"


e.g.  Set time zone as Asia/Calcutta

export TZ="/usr/share/zoneinfo/Asia/Calcutta"



How to change the Time Zone configuration after installation in RHEL3/4/5




To change your time zone configuration after you have completed the installation, use the Time and Date Properties Tool.

#redhat-config-date(RHEL 3) or 


#system-config-date (RHEL 4/5) 


Launch the Time and Date Properties Tool.

To run the Time and Date Properties Tool as a text-based application, use the command timeconfig or setup

#timeconfig

or

#setup -> TimeZone Configuration



How to change system timezone from the command line without using system-config-date or setup in RHEL5


In order to change the timezone of the system modify the file /etc/sysconfig/clock on RHEL 5

#ZONE="America/New_York"
ZONE="GMT"
UTC=true
ARC=false

For RHEL6, modify the files /etc/sysconfig/clock and the 3rd line of /etc/adjtime (LOCAL or UTC):

/etc/sysconfig/clock

ZONE="America/New_York"
/etc/adjtime

0.000421 1317770707 0.000000
1317770707
LOCAL

See /usr/share/doc/initscripts-*/sysconfig.txt for more information.


The compiled time zone files are located under the directory /usr/share/zoneinfo.  To set the timezone to that of Calcutta set the ZONE variable to the following:

ZONE="Asia/Calcutta"

Finally save the file /etc/sysconfig/clock and on next reboot, the system will be set to the defined timezone.

For the time on the machine to reflect the changed timezone, link the zoneinfo file to /etc/localtime. This can be done as bellow .

To set  Timezone to "Asia/Calcutta" link the following file to /etc/localtime:

# ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime

If  /usr is not part of your root partition copy the zone file

# cp /usr/share/zoneinfo/Asia/Calcutta /etc/localtime


Use the date command to see the changed timezone.

# date
Thu Jul 30 20:06:23 IST 2012

No comments:

Post a Comment