107.3 Localization and InternationalizationEdit

Candidates should be able to localize a system in a different language than English. As well, an understanding of why LANG=C is useful when scripting.

Key Knowledge Areas

  • Locale settings.
  • Timezone settings.

Time is very important on the Linux System. Many facilities such as Anacron, Crontab, Backup, Restore, Update Managers all need accurate time to be able to perform their executions well. Developments in computing have resulted in computer systems that are able to keep time even when the computer is switched off.

There are 2 kinds of clocks on the Linux system;

Hardware Clock aka RTC, RealTimeClock, CMOS Clock, BIOS Clock. This clock runs independent of the Operating System and runs even when the computer is turned OFF, as long as the CMOS battery lasts.

Software Clock aka System Clock. This clock runs via the system timer interrupt. Normally, it will count the number of seconds since 1st Jan 1970. Is the main clock under Linux. At boot time it reads the hardware clock and continues alone from there.

Under Linux 2 main programs are used to control the 2 clocks. The hardware clock can be directly changed with the hwclock utility. The main options are:

-r or –-show prints the current times

-w or –-systohc set the hardware clock to the current system time

-s or –-hctosys set the system time to the current hardware clock time

# date; hwclock; hwclock -s; date

Mon Jul 9 22:20:23 EDT 2007

Mon 09 Jul 2007 11:19:01 PM EDT -0.414881 seconds

Mon Jul 9 23:19:02 EDT 2007

The System Clock is controlled by the date facility. It can also be used to show the System time.

Syntax: date [options]

Options include: +text_and_metacodes

To display System time, using the date utility, you can issue a command like:

date "+It is now %H Hours and %M Minutes"

Will have the following result: It is now 14 Hours and 33 Minutes

Setting the Time and Date in Linux

You can set the time using 2 relatively simple procedures:

1) Set the Hardware clock to UTC via the BIOS setup.

2) Set the environment variable TZ to the proper time zone using the script: tzselect

The System date on the other hand can be changed with the date command. The syntax is:

date MMDDhhmmCCYY[.ss]

Note:In the file /etc/adjtime the correction factor can be saved to keep the clock as accurate as possible.

# cat /etc/adjtime

0.000990 1184019960 0.000000



# cat /etc/adjtime

-0.003247 1182889954 0.000000



Time Zone Configuration

The time zone is a simply a measure of the difference of your local time from UTC. The /usr/share/zoneinfo file will store information on all available time zones. On many modern systems, this file the /usr/share filesystem needs to be mounted when the local time zone information is needed early in the boot process.

Some countries, in addition to UCT (used interchangeably with UTC) time, apply “day light saving”, a phenomenon where clocks are moved an hour ahead or behind at a specific date every year. Such policies are available on a Linux system in /usr/share/zoneinfo/. As long as the appropriate zone file is copied to /etc/localtime, a user can ensure that Time Zone's policies are in effect.

For example if we copy /usr/share/zoneinfo/Nairobi to /etc/localtime the next time we run date this will give us the time in Nairobi. This is because date will read /etc/localtime each time it is run.

# cat /etc/timezone


# cat /etc/sysconfig/clock

# The ZONE parameter is only evaluated by system-config-date.

# The timezone of the system is defined by the contents of /etc/localtime.




Setting System time with tzconfig

You can use the tzconfig utility to modify your time zone.

# tzconfig

Your current time zone is set to France/Paris

Do you want to change that? [n]:

Your time zone will not be changed

Using NTP

NTP stands for Network Time Protocol. It is defined in RFC1305 to provide for the transfer and maintenance of time functions over multiple network systems. One of the commonest NTP servers in use is ntpd (ntp.isc.org) It works by correcting with delicate accuracy, any differences of the system clock, as opposed to large adjustments at once or within very few hours.

The computer synchronizes its time by sending messages to the time server. The time returned is adjusted by an offset of half the round-trip delay. As a result, the accuracy of the time is therefore dependent on the network latency in both directions. Faster networks (the shorter the path to a time server), are likely to have a more accurate time.

Graphically, you should be able to set your NTP time servers using a dialog similar to that in the figure below.

Ict-innovation-LPI-Fig-107-3 1.png

Figure 107.3-2. Setting NTP servers

NTP configurations are kept in /etc/ntp.conf, but the ntpd daemon has to be restarted after you save any changes to the configuration file.

Configuring a client to query an NTP server:

An NTP daemon called ntpd is used to regularly query a remote time server. All that is needed is a server entry in /etc/ntp.conf pointing to a public or corporate NTP server. Public NTP servers can be found online.

The NTP protocol can also estimate the frequency errors of the hardware clock from a sequence of queries, this estimate is written to a file referred to by the driftfile tag.

NTP Commands

The ntpdate command can be used to set system time from an NTP time server as shown below


# ntpdate 0.us.pool.ntp.org

10 Jul 10:27:39 ntpdate[15308]: adjust time server offset -0.007271 sec

NTP servers run in round robin mode, so its possible that the next time you run ntpdate, a different server will be queried. The pool from which a server is selected can be viewed when u dig your DNS, as shown below.

Round robin NTP server pool

# dig 0.pool.ntp.org +noall +answer | head -n 5

0.pool.ntp.org. 1062 IN A

0.pool.ntp.org. 1062 IN A

0.pool.ntp.org. 1062 IN A

0.pool.ntp.org. 1062 IN A

0.pool.ntp.org. 1062 IN A

The ntpdate command can be effected using ntpd with the -q option, as shown below.

Setting system time using ntpd -q

# ntpd -q

ntpd: time slew -0.014406s

Note: ntpd command uses the time server information from /etc/ntp.conf. If the ntpd daemon is running,ntpd-q will quietly exit, leaving a failure message in /var/log/messages.The NTP daemon itself can be queired using the ntpq command.

The following is a partial list of the files, terms and utilities that were used

  • /etc/timezone
  • /etc/localtime
  • /usr/share/zoneinfo
  • Environment variables:
    • LC_*
    • LC_ALL
    • LANG
  • /usr/bin/locale
  • tzselect
  • tzconfig
  • date
  • iconv
  • UTF-8
  • ISO-8859
  • Unicode

Previous Chapter | Next Chapter

Last modified on 9 October 2012, at 21:38