fbpx locale Command in Linux: Setting Language and Encoding | Certificação Linux

locale Command in Linux: Setting Language, Timezone and Date Format

📅 01/01/2019 ⏱ 3 min ✍️ Uira Ribeiro
Linuxcommands
locale Command in Linux: Setting Language, Timezone and Date Format
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The locale command in Linux works with environment variables that define the system's internationalization, such as characters, dates, and number formatting.

Linux maintains a list of environment variables to define language internationalization standards, number format, time format, date format, currency format, among others.

The variables are:

  • LC_COLLATE: defines character or string collation grouping information;
  • LC_CTYPE: defines the character encoding type;
  • LC_MONETARY: defines how numbers are written, whether they use a period or comma to separate decimals;
  • LC_MESSAGES: defines the format of affirmative and negative responses;
  • LC_NUMERIC: defines a list of rules and symbols for formatting non-monetary numeric information;
  • LC_TIME: defines how time is written;
  • LC_ALL: defines a pattern that encompasses all other settings above.

locale

The locale command displays these environment variables.

$ localeLANG=pt_BR.UTF-8LANGUAGE=LC_CTYPE="pt_BR.UTF-8"LC_NUMERIC="pt_BR.UTF-8"LC_TIME="pt_BR.UTF-8"LC_COLLATE="pt_BR.UTF-8"LC_MONETARY="pt_BR.UTF-8"LC_MESSAGES="pt_BR.UTF-8"LC_PAPER="pt_BR.UTF-8"LC_NAME="pt_BR.UTF-8"LC_ADDRESS="pt_BR.UTF-8"LC_TELEPHONE="pt_BR.UTF-8"LC_MEASUREMENT="pt_BR.UTF-8"LC_IDENTIFICATION="pt_BR.UTF-8"LC_ALL=pt_BR.UTF-8

The LC_ALL variable can be used to configure all the others.

The "-a" option displays the list of available locales:

$ locale -aen_US.utf8pt_BR.utf8

The desired locale is not always available on the system. If it does not appear with the "-a" option of the locale command, it is necessary to generate the locale.

To see the list of all locales that can be generated, check the contents of the file /etc/locale.gen:

$ cat /etc/locale.gen# aa_DJ ISO-8859-1# aa_DJ.UTF-8 UTF-8# aa_ER UTF-8( ... )

To generate the desired locale and be able to use it in the LC_ALL variable, the locale-gen command is used to generate the locale:

$ locale-gen pt_BR.UTF-8Generating locales (this might take a while)...  pt_BR.UTF-8... doneGeneration complete.

To change the locale configuration, simply change the LC_ALL variable:

$ export LC_ALL=pt_BR.UTF-8

Since the locale is configured through environment variables, they need to be in the shell startup script or profile to remain permanent on the system.

localectl Command

The systemd localectl service can be used to query and change the system locale and keyboard layout settings.

This service can be used to control the language settings of system services and the user interface before the user logs in.

Example:

To view the configured locale:

$ localectl status   System Locale: LANG=en_US.UTF-8       VC Keymap: n/a      X11 Layout: n/a

To change the locale:

$ sudo localectl set-locale LC_TIME=en_IN.UTF-8

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Like it? Share it

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp