The locale command without any options displays the contents of the /usr/bin/locale file. The /usr/bin/locale file contains the language, country, and character encoding standard for various environment variables. In the example, the variables are set to en_US.utf8 (English, USA, Unicode).
Locale controls things that are unique to a region or demographic. For example, in the USA, the size of a piece of paper is measured in inches. In Europe, the size of a piece of paper is measured in milliimeters (mm). Setting a locale to France or USA will impact how an application displays paper size when printing.
[root@server1 ~]# locale LANG=en_US.utf8 LC_CTYPE="en_US.utf8" LC_NUMERIC="en_US.utf8" LC_TIME="en_US.utf8" LC_COLLATE="en_US.utf8" LC_MONETARY="en_US.utf8" LC_MESSAGES="en_US.utf8" LC_PAPER="en_US.utf8" LC_NAME="en_US.utf8" LC_ADDRESS="en_US.utf8" LC_TELEPHONE="en_US.utf8" LC_MEASUREMENT="en_US.utf8" LC_IDENTIFICATION="en_US.utf8" LC_ALL=
All possible locales
The -a or --all-locales option displays all of the possible locales that can be used. A very long list of locales will be displayed.
[root@server1 ~]# locale -a . . . en_US en_US.iso88591 en_US.iso885915 en_US.utf8 es_US es_US.iso88591 es_US.utf8 unm_US unm_US.utf8 yi_US yi_US.cp1255 yi_US.utf8 . . .
If the locale you want to use is not listed, you can use the locale-gen command to generate the locale. The locale you want to generate must be in the /etc/locale.gen file.
[root@server1 ~]# locale-gen fr_FR.iso885915
Following are popular character encoding standards.
- UTF-8 / Unicode
- ISO-8859-1 lacks some of the characters used by Western European Languages, especially French
- ISO-8859-15 is typically used for Western European Languages, especially French
- ASCII - Legacy character encoding standard
The last environmental variable in the /usr/bin/locale file is LC_ALL. The LC_ALL variable will override all of the other variables beginning with LC.
In this example, a .txt file was created in Windows Notepad, and the file contains the special character â.
When attempting to view this file using a Linux text editor, the â character may not be displayed. This problem occurs because the text editor or the Linux system may not use a character encoding standard that supports the â character.
One solution to this problem is to update the LC_ALL variable in the /usr/bin/locale file to use a character encoding standard that supports the â character, such as UTF8.
The Linux text editor now properly displays the â character.
However, setting the LC_ALL variable to use UTF8 may not be an ideal solution, because this would update the entire operating system to use UTF8. The iconv command can be used to update the file to use UTF8.