Configuring the Time Zone
During the initial installation of your Linux system, you are prompted to specify the time zone the
system is located in. On some distributions (such as Ubuntu), the time zone you specify is saved
in the
/etc/timezone
file. You can view your system’s current time zone by displaying the contents
of this file at the shell prompt using the cat command. Here’s an example:
rtracy@ubuntu:~$ cat /etc/timezone
America/Denver
Other distributions (such as openSUSE) save this information in the /etc/sysconfig/clock file
instead. The TIMEZONE= directive in this file configures the zone file to use, as you see here:
TIMEZONE="America/Boise"
You can also view the current time zone by entering
date
at the shell prompt, as shown next:
openSUSE:~ # date
Wed Feb 9 11:40:05 MST 2014
openSUSE:~ #
If you need to change time zones after installation, you can use the
tzselect
or
tzconfig
command at the shell prompt. Debian-based distributions use the tzconfig command whereas other
distributions such as openSUSE and Fedora use the tzselect command. This command must be
run as root.
Here is an example:
openSUSE:~ # tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
The tzselect command first displays a list of continents and oceans. Enter the appropriate
number for the region where the time zone you want to switch to is located. When you do, a list
of countries in the region is displayed. Enter the number for the country where the system will be located; then enter the number for the appropriate time zone.
You are prompted to confirm the time zone change, as shown in this example:
The following information has been given:
United States
Mountain Time
Therefore TZ='America/Denver' will be used.
Local time is now: Wed Feb 9 11:50:10 MST 2011.
Universal Time is now: Wed Feb 9 18:50:10 UTC 2011.
Is the above information OK?
1) Yes
2) No
#?
If the change is correct, enter
1
to confirm.
Notice in the preceding example that tzselect switches time zones by setting the value of the
TZ environment variable.
You can actually change time zones from the shell prompt without tzselect by setting the value of the TZ environment variable and then exporting it. This is useful in situations where you don’t have the root password for the system or if you want to use a different time zone for your account without changing the time zone used by other users. The syntax is
export TZ=time_zone
A list of available time zones can be found in the
/usr/share/zoneinfo/
directory, as shown here:
openSUSE:~ # ls /usr/share/zoneinfo/
Africa Canada Factory Iceland MST7MDT Portugal Zulu
America Chile GB Indian Mexico ROK iso3166.tab
Antarctica Cuba GB-Eire Iran Mideast Singapore posix
Arctic EET GMT Israel NZ Turkey posixrules
Asia EST GMT+0 Jamaica NZ-CHAT UCT right
Atlantic EST5EDT GMT-0 Japan Navajo US zone.tab
Australia Egypt GMT0 Kwajalein PRC UTC
Brazil Eire Greenwich Libya PST8PDT Universal
CET Etc HST MET Pacific W-SU
CST6CDT Europe Hongkong MST Poland WET
ws1:~ #
Be aware that this change is not persistent. If you reboot your system, the time zone change
will be lost. You can make the time zone change persistent for your user account by adding the
following to the
.profile
file in your user’s home directory:
export TZ='America/Denver'
You can also change time zones using the
/etc/localtime
file and the various zone files in
/usr/ share/zoneinfo
that we looked at earlier.
To do this, create a symbolic link to the appropriate time zone file in
/usr/share/zoneinfo
from
/etc/localtime
For example, if you wanted to switch to the Mountain Standard Time zone in the United States, you would enter
ln –sf /usr/share/zoneinfo/MST /etc/localtime
at the shell prompt.
LX0-104 Exam Objectives (M)
No comments:
Post a Comment