A locale is a definition of language (and encoding, e.g. UTF-8), time, currency, and other number formats, that vary by language and geographical region. Related formats are grouped into categories. *nix systems include a number of environment variables (one per category) you can use to pick these data formats, by specifying a locale for each.
The settings in a locale reflect a language's and geographic region's
(i.e., country's or territory's) cultural rules for formatting data.
A locale name looks like
lang part is required.
locales are always defined, but others may or may not be defined (installed)
on any given system.
A locale can also be an absolute pathname to a file produced by the
The POSIX categories and the environment variables for each are:
(Additional categories such as
LC_PAPER may be available on some
LC_* variable is not set, the value of
LANG is used to define its locale.
LC_ALL is set, that value
over-rides any other
You can see the current values used for each category, and details
on each installed locale, by using the
To portably set your locale, it is best to set the
LC_ALL environment variable to
Setting only (for example)
it is ineffective if
LC_ALL is also set,
and it has undefined behavior if
LC_CTYPE is unset)
is set to an incompatible value.
For example, you get undefined behavior if
Most shell scripts probably should set
POSIX at the top of the script.
(You may want to set
UTC0 as well, especially for utilities
that record a date in the current timezone such as
The standard utility
iconv can be used
to convert between (compatible) text encodings.
iconv -l to list all available encodings
on your system.