locale Command in Linux

Introduction to Linux Locales

In this hands-on lab, we will delve into the Linux locale command and its various practical uses for systemadmin tasks. We'll start by understanding what locales are and how they define crucial settings like language, country, character encoding, and cultural preferences for both applications and the underlying operating system. Then, we'll learn to list available locales on your Linux system and explore their structure. Finally, we will modify the system locale and examine how this change impacts system behavior, focusing on date formats and application language settings. This lab aims to equip you with a strong understanding of managing and customizing locale settings within a Linux environment for optimal system administration.

Understanding Locales in Linux

This section explores the core concept of locales within a Linux operating system. Locales control how software adapts to different regional and language requirements. Specifically, locales dictate the language, country-specific conventions, character encoding, and other culturally relevant preferences utilized by applications and the system itself.

Let's begin by examining the current locale settings configured on your system:

locale

Example output:

LANG=en_US.UTF-8
LANGUAGE=
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 provided output illustrates that the system is currently configured to use the en_US.UTF-8 locale. This indicates English language settings for the United States, using UTF-8 character encoding. This is important for systemadmin tasks that rely on consistent language and encoding.

Locales play a vital role in ensuring applications and the OS display information, such as dates, numbers, and currency values, in a format suitable for the user's specific language and cultural norms.

Exploring Available Locales

This section focuses on discovering the range of locales that are available on your Linux system. We'll learn how to generate a comprehensive list of these locales, crucial for systemadmin to choose the best language setting.

To list all installed locales on your Linux installation, execute the following command:

locale -a

This command will output a list of every locale currently available. The output will be a comprehensive list of locale names, similar to this example:

C
C.UTF-8
en_AG
en_AG.UTF-8
en_AU.UTF-8
en_BW.UTF-8
en_CA.UTF-8
en_DK.UTF-8
en_GB.UTF-8
en_HK.UTF-8
en_IE.UTF-8
en_IN
en_IN.UTF-8
en_NG
en_NG.UTF-8
en_NZ.UTF-8
en_PH.UTF-8
en_SG.UTF-8
en_US.UTF-8
en_ZA.UTF-8
en_ZM
en_ZM.UTF-8
en_ZW.UTF-8
## ... (more locales)

Locale names adhere to the language_COUNTRY.ENCODING format, where:

  • language represents the ISO 639-1 language code (e.g., en signifies English)
  • COUNTRY represents the ISO 3166-1 alpha-2 country code (e.g., US for the United States)
  • ENCODING specifies the character encoding scheme (e.g., UTF-8)

You can refine your search using locale -a | grep to find specific locales. For example:

locale -a | grep en_US

This will display only the locales related to United States English, simplifying the selection process for systemadmin.

Changing the System Locale and Observing the Effects

In this final stage, we'll modify the system locale and examine how these changes manifest in various aspects of the system's behavior, a critical skill for any systemadmin.

First, confirm the current locale settings:

locale

Now, let's switch the system locale to a different one. For this example, we'll use French (France):

sudo localectl set-locale LANG=fr_FR.UTF-8

After executing this command, the system locale should be updated. Verify the change:

locale

The output should now reflect the new locale settings, displaying LANG=fr_FR.UTF-8. This may require root privileges.

To observe the impact of the altered locale, try the following checks:

  1. Display the current date and time:

    date

    The date and time output should now be displayed in French.

  2. Open the calculator application and observe the decimal separator and thousands separator:

    gnome-calculator
  3. Open a text editor and observe the default language of the spell checker:

    gedit
  4. Check the language of the system menus and applications:
    Explore the system settings, terminal, and other applications to see how the language has changed.

After examining the effects, revert the locale back to the original en_US.UTF-8:

sudo localectl set-locale LANG=en_US.UTF-8

Confirm the locale change by rerunning the locale command.

Summary of Linux Locale Management

In this lab, we began by defining locales in Linux, which are settings that determine the language, country, character encoding, and other cultural adaptations used by applications and the operating system. We then learned to check the current system locale settings and understand their meaning. We explored the available locales by listing all installed options and examining the structure of locale names. Finally, we modified the system locale and observed its effects on displaying information and application behavior, empowering systemadmin to effectively manage internationalization settings.

400+ Linux Commands