Linux locale Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux locale command and its practical applications. We will first understand the concept of locales, which define the language, country, character encoding, and other cultural preferences used by applications and the operating system. Then, we will explore the available locales on the system and learn how to list them. Finally, we will change the system locale and observe the impact on the system's behavior. This lab will provide you with a solid understanding of how to manage and customize the locale settings in a Linux environment.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/TextProcessingGroup(["`Text Processing`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/VersionControlandTextEditorsGroup(["`Version Control and Text Editors`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/TextProcessingGroup -.-> linux/grep("`Pattern Searching`") linux/UserandGroupManagementGroup -.-> linux/env("`Environment Managing`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/VersionControlandTextEditorsGroup -.-> linux/gedit("`Graphical Text Editing`") linux/SystemInformationandMonitoringGroup -.-> linux/date("`Date/Time Displaying`") subgraph Lab Skills linux/echo -.-> lab-422763{{"`Linux locale Command with Practical Examples`"}} linux/grep -.-> lab-422763{{"`Linux locale Command with Practical Examples`"}} linux/env -.-> lab-422763{{"`Linux locale Command with Practical Examples`"}} linux/ls -.-> lab-422763{{"`Linux locale Command with Practical Examples`"}} linux/gedit -.-> lab-422763{{"`Linux locale Command with Practical Examples`"}} linux/date -.-> lab-422763{{"`Linux locale Command with Practical Examples`"}} end

Understand the Concept of Locales

In this step, we will explore the concept of locales in Linux. Locales are settings that define the language, country, character encoding, and other cultural preferences used by applications and the operating system.

To begin, let's check the current locale settings on the 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 output shows that the system is currently using the en_US.UTF-8 locale, which represents the English language, United States, and UTF-8 character encoding.

Locales are important for ensuring that applications and the operating system display information, such as dates, numbers, and currency, in a way that is appropriate for the user's language and cultural preferences.

Explore the Available Locales on the System

In this step, we will explore the available locales on the system and understand how to list them.

To view the list of all installed locales, run the following command:

locale -a

This will display all the locales available on the system. The output will be a long list of locale names, such as:

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)

The locale names follow the format language_COUNTRY.ENCODING, where:

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

You can also use the locale -a | grep command to search for specific locales, for example:

locale -a | grep en_US

This will display all the locales related to the United States English locale.

Change the System Locale and Observe the Impact

In this final step, we will change the system locale and observe the impact on various aspects of the system.

First, let's check the current locale settings:

locale

Now, let's change the system locale to a different one, for example, French (France):

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

After running this command, the system locale should have changed. Let's verify it:

locale

You should see the new locale settings, with LANG=fr_FR.UTF-8.

To observe the impact of the changed locale, try the following:

  1. Display the current date and time:

    date

    The output should now be 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 exploring the impact, let's change the locale back to the original en_US.UTF-8:

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

Verify the locale change by running locale again.

Summary

In this lab, we first explored the concept of locales in Linux, which are settings that define the language, country, character encoding, and other cultural preferences used by applications and the operating system. We then learned how to check the current locale settings on the system and understand the information provided. Next, we explored the available locales on the system by listing all the installed locales, and we discussed the format of the locale names. Finally, we learned how to change the system locale and observe the impact on the display of information.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like