Menu
Localisation and internationalisation
“Locales, LANG and LC_* variables, time zones and TZ, and character encodings from ASCII to UTF-8.”
A server in Frankfurt, an admin in Toronto, a customer file from 1998 with accented names: computers have to agree on how to show dates, numbers and letters for people all over the world. Linux splits that into two ideas. Internationalisation (shortened to i18n: 18 letters between the i and the n) is making software able to adapt. Localisation (l10n) is the actual adapting: German month names, a comma as the decimal sign, the Berlin time zone.
As an admin you set three things: the locale (language and formats), the time zone, and the character encoding files are stored in.
Character encodings: ASCII to UTF-8#
A file is just bytes. An encoding is the table that maps bytes to characters. You’ll meet four names:
| Name | Size | What it covers |
|---|---|---|
| ASCII | 7 bits, 128 characters | English letters, digits, punctuation, control codes. Nothing else |
| ISO-8859 | 8 bits, 256 characters | A family of 15 one-byte tables: ASCII plus 128 extra characters for one region. ISO-8859-1 (Latin-1) is Western Europe, ISO-8859-15 adds the € sign |
| Unicode | A list, not an encoding | One number (code point) for every character in every script: é is U+00E9, € is U+20AC |
| UTF-8 | 1 to 4 bytes per character | The usual way to store Unicode. The first 128 characters are identical to ASCII |
UTF-8 is the default on every current Linux system. Look at how the same letter becomes different bytes:
$ printf 'A' | od -An -tx1
41
$ printf 'é' | od -An -tx1
c3 a9
$ printf '€' | od -An -tx1
e2 82 ac
A is one byte, the same as in ASCII. é takes two bytes in UTF-8, while in ISO-8859-1 it was the single byte
e9. When a program reads UTF-8 bytes as Latin-1, c3 a9 shows up as two characters: é. That’s the
classic broken-accent look, called mojibake.
Converting with iconv#
iconv converts text from one encoding to another. -f is “from”, -t is “to”:
$ printf 'caf\xe9\n' > latin1.txt # é as one ISO-8859-1 byte
$ file latin1.txt
latin1.txt: ISO-8859 text
$ iconv -f ISO-8859-1 -t UTF-8 latin1.txt -o utf8.txt
$ file utf8.txt
utf8.txt: Unicode text, UTF-8 text
$ cat utf8.txt
café
Without -o, iconv writes to standard output, so iconv -f ISO-8859-1 -t UTF-8 old.txt > new.txt works too.
More things to know:
iconv -l # list every encoding iconv knows
echo 'Crème brûlée' | iconv -f UTF-8 -t ASCII//TRANSLIT # Creme brulee
iconv -f UTF-8 -t ASCII//IGNORE in.txt # drop what doesn't fitWithout //TRANSLIT or //IGNORE, iconv stops with an error at the first character the target can’t hold.
//TRANSLIT uses the rules of your current locale. Under the plain C locale you may get Cr?me br?l?e instead, so run it with a UTF-8 locale like en_US.UTF-8.Locales#
A locale is a named bundle of rules: language for messages, date and time format, number format, currency, sort order, which characters are letters. Its name looks like this:
language_TERRITORY.codeset@modifier
de_DE.UTF-8 German as used in Germany, UTF-8
en_GB.UTF-8 English as used in the UK
nl_BE.UTF-8 Dutch as used in Belgium
sr_RS.UTF-8@latin Serbian, written in Latin lettersTwo special locales exist everywhere: C (also called POSIX), the plain, English, ASCII behaviour of classic
Unix, and C.UTF-8, the same rules but with UTF-8 characters.
The variables#
The locale is picked through environment variables, one per category:
| Variable | Controls | Example difference |
|---|---|---|
LC_CTYPE | Character classes and encoding | Is é a letter? How many bytes per character? |
LC_NUMERIC | Number format | 3.14 or 3,14, 1,000 or 1.000 |
LC_TIME | Date and time format | Tue Dec 1 or Di 1. Dez |
LC_COLLATE | Sort order | A B a b or a A b B |
LC_MONETARY | Currency | $, €, where the sign goes |
LC_MESSAGES | Language of program messages | No such file or directory or Datei oder Verzeichnis nicht gefunden |
LC_PAPER | Paper size | Letter or A4 |
LC_MEASUREMENT | Units | Imperial or metric |
LC_NAME, LC_ADDRESS, LC_TELEPHONE | Formats for names, addresses, phone numbers | |
LC_IDENTIFICATION | Information about the locale itself |
On top of those, two special variables:
LANGis the default for every category that isn’t set on its own.LC_ALLoverrides every category, whatever else is set.
So the order of precedence is: LC_ALL, then LC_xxx, then LANG. If none is set, you get C.
LANGUAGE, a fallback list for message translations only: LANGUAGE=nl:de:en means Dutch, else German, else English.Looking at it: the locale command#
/usr/bin/locale shows what’s in effect:
$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="de_DE.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=
Values in quotes are derived (here from LANG). Here LC_TIME was set on its own, so it differs. Other useful forms:
$ locale -a # locales installed on this machine
C
C.utf8
en_US.utf8
POSIX
$ locale charmap # the encoding in use
UTF-8
Seeing the effect#
Set a variable just for one command to try it out:
$ printf 'b\nA\na\nB\n' | LC_ALL=C sort
A
B
a
b
$ printf 'b\nA\na\nB\n' | LC_ALL=en_US.UTF-8 sort
a
A
b
B
$ LC_ALL=de_DE.UTF-8 date
Di 1. Dez 14:30:00 CET 2026
$ LC_ALL=de_DE.UTF-8 printf "%'d\n" 1234567
1.234.567
The C locale sorts by byte value, so all capitals come first. That’s why scripts often start with
export LC_ALL=C: the output of sort, ls and grep ranges like [a-z] stays the same on every machine.
If you ask for a locale that isn’t installed, you get a warning and the C rules:
$ export LC_ALL=fr_FR.UTF-8
bash: warning: setlocale: LC_ALL: cannot change locale (fr_FR.UTF-8)
$ date
Tue Dec 1 14:30:00 CET 2026
$ unset LC_ALL
Setting the locale for the system and for a user#
Minimal containers ship only C, C.UTF-8 and POSIX. Generating or installing more is distribution specific:
# Debian / Ubuntu
sudo apt install locales # usually already there on a full install
sudo dpkg-reconfigure locales # menu: pick locales and the default
# or by hand: uncomment "de_DE.UTF-8 UTF-8" in /etc/locale.gen, then
sudo locale-gen
sudo update-locale LANG=de_DE.UTF-8 # writes /etc/default/locale
# RHEL / Fedora
sudo dnf install glibc-langpack-de # one package per languageOn any systemd machine, localectl reads and sets the system default:
$ localectl status
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
$ sudo localectl set-locale LANG=de_DE.UTF-8
The system default is stored in /etc/locale.conf (RHEL, Fedora, Arch) or /etc/default/locale (Debian,
Ubuntu). It’s read at login. A single user can override it in ~/.bashrc or ~/.profile:
export LANG=nl_NL.UTF-8
export LC_MESSAGES=en_US.UTF-8 # Dutch formats, English error messagesTip
Keep LC_ALL out of profiles. It’s meant for a quick override of one command or script. Set LANG plus the
few LC_* you want to change instead.
Time zones#
The kernel’s clock counts in UTC. Every program converts that to local time when it shows it, using the
time zone database: one small binary file per region in /usr/share/zoneinfo/ (package tzdata). A zone like
Europe/Berlin knows its offset from UTC and every daylight saving switch in its history.
$ ls /usr/share/zoneinfo/Europe | head -4
Amsterdam
Andorra
Astrakhan
Athens
The system time zone: /etc/localtime and /etc/timezone#
/etc/localtime decides the system’s zone. Nowadays it’s a symbolic link into the database:
$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 33 Dec 1 10:00 /etc/localtime -> /usr/share/zoneinfo/Europe/Berlin
On older systems it may be a copy of the zone file instead of a link. Debian and Ubuntu also keep the zone name in
a plain text file, /etc/timezone, that some tools still read:
$ cat /etc/timezone
Europe/Berlin
RHEL and Fedora don’t use /etc/timezone.
Changing it: timedatectl#
timedatectl is the systemd tool, and the easiest way on any current distribution:
$ timedatectl
Local time: Tue 2026-12-01 14:30:00 CET
Universal time: Tue 2026-12-01 13:30:00 UTC
RTC time: Tue 2026-12-01 13:30:00
Time zone: Europe/Berlin (CET, +0100)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
$ timedatectl list-timezones | grep -i toronto
America/Toronto
$ sudo timedatectl set-timezone America/Toronto
Without systemd, or to understand what that command does, change the link yourself:
sudo ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
echo "America/Toronto" | sudo tee /etc/timezone # Debian and Ubuntu onlyOn Debian and Ubuntu, sudo dpkg-reconfigure tzdata does both with a menu.
Finding your zone: tzselect#
Not sure of the exact name? tzselect asks a few questions (continent, country, sometimes a region) and prints the
TZ value:
$ tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
...
#? 2
Please select a country whose clocks agree with yours.
...
Therefore TZ='America/Toronto' will be used.
...
You can make this change permanent for yourself by appending the line
TZ='America/Toronto'; export TZ
to the file '.profile' in your home directory; then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
America/Toronto
tzselect changes nothing on the system. It only tells you the name. That’s a common exam trick.
Per user and per command: the TZ variable#
The TZ environment variable overrides /etc/localtime for one process, or for a user who exports it in
~/.profile. It’s handy to see the time elsewhere:
$ date +"%F %T %Z"
2026-12-01 14:30:00 CET
$ TZ=Asia/Tokyo date +"%F %T %Z"
2026-12-01 22:30:00 JST
$ TZ=America/New_York date +"%F %T %Z"
2026-12-01 08:30:00 EST
$ date -u +"%F %T %Z"
2026-12-01 13:30:00 UTC
A user on a shared server who lives elsewhere can add export TZ="America/Toronto" to their ~/.profile. The
system keeps its own zone, their shell shows their local time.
More date tricks#
date shows the time in whatever format you ask for, using the current locale and zone:
$ date
Tue Dec 1 02:30:00 PM CET 2026
$ date +"%A %d %B %Y, %H:%M"
Tuesday 01 December 2026, 14:30
$ date -d "next friday" +%F
2026-12-04
$ date -d @0 -u
Thu Jan 1 12:00:00 AM UTC 1970
$ date +%s
1796131800
(The first and last lines use the en_US.UTF-8 12-hour format. Under C you’d see 14:30:00 and 00:00:00.)
Setting the clock with date and hwclock is part of the next topic, system time.
Exam checklist#
- Locale names:
language_TERRITORY.codeset, for examplede_DE.UTF-8.CandPOSIXare the plain default. - Precedence:
LC_ALLbeatsLC_*beatsLANG.LC_ALL=Cgives scripts predictable sorting and output. localeshows the settings,locale -athe installed locales.LC_TIME,LC_NUMERIC,LC_COLLATE,LC_MESSAGESare the ones to know by heart.- System locale:
/etc/locale.conf(RHEL) or/etc/default/locale(Debian), orlocalectl set-locale. /etc/localtimeis a link to (or copy of) a file in/usr/share/zoneinfo/./etc/timezoneholds the zone name on Debian and Ubuntu.timedatectl set-timezone Zone/Citychanges the system zone.tzselectonly helps you find the name.TZ=Zone/Cityoverrides the zone for one command or one user.date -ushows UTC.- ASCII is 7-bit, ISO-8859-x is 8-bit per region, Unicode is the character list, UTF-8 stores it in 1 to 4 bytes and is ASCII compatible.
iconv -f FROM -t TO file,iconv -llists encodings,//TRANSLITapproximates characters the target lacks.
Answer these 3 questions to commit this byte to your learning path.
Reset. This byte isn't committed any more. Answer the questions again to commit it.
$ git commit -m "learn(lpic-107): Localisation and internationalisation"
[main 181b81a] learn(lpic-107): Localisation and internationalisation
1 byte changed, 3 insertions(+)
See it on your path Already committed . Try the questions again any time, it won't undo anything. To uncommit it and start over: