Menu

Administrative Tasks

Step 3 of 3 LPIC-1 107.3weight 3

Localisation and internationalisation

“Locales, LANG and LC_* variables, time zones and TZ, and character encodings from ASCII to UTF-8.”

View .md

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:

NameSizeWhat it covers
ASCII7 bits, 128 charactersEnglish letters, digits, punctuation, control codes. Nothing else
ISO-88598 bits, 256 charactersA 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
UnicodeA list, not an encodingOne number (code point) for every character in every script: é is U+00E9, € is U+20AC
UTF-81 to 4 bytes per characterThe 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:

console
$ 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”:

console
$ 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:

bash
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 fit

Without //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:

text
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 letters

Two 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:

VariableControlsExample difference
LC_CTYPECharacter classes and encodingIs é a letter? How many bytes per character?
LC_NUMERICNumber format3.14 or 3,14, 1,000 or 1.000
LC_TIMEDate and time formatTue Dec 1 or Di 1. Dez
LC_COLLATESort orderA B a b or a A b B
LC_MONETARYCurrency$, €, where the sign goes
LC_MESSAGESLanguage of program messagesNo such file or directory or Datei oder Verzeichnis nicht gefunden
LC_PAPERPaper sizeLetter or A4
LC_MEASUREMENTUnitsImperial or metric
LC_NAME, LC_ADDRESS, LC_TELEPHONEFormats for names, addresses, phone numbers
LC_IDENTIFICATIONInformation about the locale itself

On top of those, two special variables:

  • LANG is the default for every category that isn’t set on its own.
  • LC_ALL overrides 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.

GNU programs also read 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:

console
$ 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:

console
$ 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:

console
$ 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:

console
$ 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:

bash
# 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 language

On any systemd machine, localectl reads and sets the system default:

console
$ 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:

~/.profilebash
export LANG=nl_NL.UTF-8
export LC_MESSAGES=en_US.UTF-8     # Dutch formats, English error messages

Tip

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.

console
$ 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:

console
$ 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:

console
$ 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:

console
$ 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:

bash
sudo ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
echo "America/Toronto" | sudo tee /etc/timezone      # Debian and Ubuntu only

On 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:

console
$ 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:

console
$ 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:

console
$ 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 example de_DE.UTF-8. C and POSIX are the plain default.
  • Precedence: LC_ALL beats LC_* beats LANG. LC_ALL=C gives scripts predictable sorting and output.
  • locale shows the settings, locale -a the installed locales. LC_TIME, LC_NUMERIC, LC_COLLATE, LC_MESSAGES are the ones to know by heart.
  • System locale: /etc/locale.conf (RHEL) or /etc/default/locale (Debian), or localectl set-locale.
  • /etc/localtime is a link to (or copy of) a file in /usr/share/zoneinfo/. /etc/timezone holds the zone name on Debian and Ubuntu.
  • timedatectl set-timezone Zone/City changes the system zone. tzselect only helps you find the name.
  • TZ=Zone/City overrides the zone for one command or one user. date -u shows 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 -l lists encodings, //TRANSLIT approximates characters the target lacks.

Byte check

0/3

Answer these 3 questions to commit this byte to your learning path.

  1. LANG=en_US.UTF-8, LC_TIME=de_DE.UTF-8 and LC_ALL=fr_FR.UTF-8 are all set. In which language does date print the day name?
  2. What is /etc/localtime on most modern systems?
  3. An old file is stored in ISO-8859-1 (Latin-1). Which command turns it into UTF-8?
Search posts and bytes

Optional account

Keep your progress everywhere

Everything on AminBytes is free to read, with or without an account. Sign in only if you want your commits, streak and merged topics saved, on every device.

or

We keep only your name, avatar and which bytes you finished, and you can delete it all anytime. Privacy