Home > Articles

This chapter is from the book

This chapter is from the book

Localization

Several commands can be used to display or modify the date and time on a system, as well as the locale of a system. This section explores these commands.

timedatectl

Use the timedatectl command to display the system clock.

Syntax:

timedatectl [option] [value]

Example:

[root@OCS ~]# timedatectl
       Local time   :       Wed 2018-10-10 14:41:41 PDT
       Universal time:      Wed 2018-10-10 21:41:41 UTC
       RTC time:            Wed 2018-10-10 09:51:09
      Timezone:             America/Los_Angeles (PDT, -0700)
      NTP enabled:          yes
       NTP synchronized:     yes
       RTC in local TZ:      no
       DST active:           yes
        Last DST change:    DST began at
                            Sun 2018-03-11 01:59:59 PST
                            Sun 2018-03-11 03:00:00 PDT
      Next DST change:  DST ends (the clock jumps one hour backwards)
at
                            Sun 2018-11-04 01:59:59 PDT
                             Sun 2018-11-04 01:00:00 PST

As the root user, you can use this command to set the system clock. Table 7.4 demonstrates the most commonly used methods of changing the system clock.

TABLE 7.4 Methods to Change the System Clock

Method

Description

set-time [time]

Sets the system clock to the specified time.

set-timezone [zone]

Sets the system time zone to the specified zone.

set-ntp [0|1]

Enables (1) or disables (0) Network Time Protocol.

localectl

The BASH shell and other processes need customized operations to fit the location of the user. For example, if currency is to be displayed and the user is located in the United States, the $ character should be used. If the user is located in Great Britain, the £ character should be used.

This section focuses on the variables used to inform programs what settings to use based on a user’s locale.

LC_* refers to a collection of locale settings used to change the way the shell and other programs handle differences based on the geographic region of the user (or a region the user is familiar with). These values can be viewed by executing the locale command:

[root@OCS ~]# locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

The most important locale settings are described in Table 7.5.

TABLE 7.5 Locale Settings

Setting

Description

LANG

Language

LC_CTYPE

Case conversion

LC_NUMERIC

Numeric format

LC_TIME

Time and date format

LC_COLLATE

Collation order

LC_MONETARY

Currency format

LC_MESSAGES

Format of message

LC_PAPER

Paper size format

LC_NAME

Name format

LC_ADDRESS

Address format

LC_TELEPHONE

Telephone format

LC_ALL

When set, LC_ALL will override all other locale settings. This provides an easy means to change all locale settings by modifying one environment variable.

The localectl command can display and change both locale values and keyboard layouts.

Syntax:

localectl [options] command

To display values, use status:

[root@OCS ~]# localectl status
 System Locale:  LANG=en_US.utf8
    VC Keymap:   us
    X11 Layout:   us
    X11 Model:    pc105+inet
     X11 Options: terminate:ctrl_alt_bksp

Set the locale and keyboard as follows:

[root@OCS ~]# localectl set-locale "LANG=de_DE.utf8"set-keymap "de"

There are a handful of options to the localectl command, but none of them are commonly used.

Pearson IT Certification Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Pearson IT Certification and its family of brands. I can unsubscribe at any time.