Locales, character encodings and time zones
Making a system speak the right language and keep the right time zone: locale variables and their precedence, character encodings, and the difference between the hardware clock and system time.
Lesson 3 of 3 in objective 107. Administrative tasks, part of LPIC-1 Exam 102-500.
Locales
A locale name looks like en_GB.UTF-8: language, territory, and the character encoding. The environment variables that select it form a precedence chain — LC_ALL overrides everything, the individual LC_* variables (LC_TIME, LC_NUMERIC, LC_COLLATE, LC_MESSAGES) set one category each, and LANG is the fallback for anything not otherwise set. So LC_ALL is the sledgehammer, and setting it is how scripts force predictable output: LC_ALL=C sorts and formats in the plain, unlocalised way, which is why so many scripts begin with it.
The precedence is what makes a single category the precise tool, and the exam asks it that way round: on a host where LANG is de_DE.UTF-8, wanting untranslated English messages while KEEPING German dates and numbers is export LC_MESSAGES=C and nothing broader. export LC_ALL=C or export LANG=C would take the formatting with it, and export LC_CTYPE=C changes which characters count as letters rather than which language anything is written in. The variable has to be exported, like DISPLAY or PATH, because what reads it is the program you are about to run and not the shell.
locale prints the current settings and locale -a lists what is available. The character encoding half matters on its own: ASCII covers 128 characters, the ISO-8859 family extended that to one byte per character per region, and Unicode covers everything — with UTF-8 the variable-width encoding of it that is compatible with ASCII for the first 128 code points. iconv converts a file between encodings.
Time zones and the two clocks
The machine has a hardware clock in its firmware and a system clock the kernel keeps. hwclock reads and writes the hardware one; date reads and sets the system one. The hardware clock is best kept in UTC, with the local time derived from it, because that is what makes daylight saving a display concern rather than a stored one.
The time zone is /etc/localtime, which is a copy of or symlink to a file under /usr/share/zoneinfo/. /etc/timezone on Debian systems names it in plain text. The TZ environment variable overrides it for one process, and timedatectl is the systemd command that reads and sets time, time zone and NTP synchronisation in one place — timedatectl set-timezone Europe/Berlin, timedatectl list-timezones.
On a machine with no systemd there is no timedatectl, and the zone is set by making that link by hand: ln -sf /usr/share/zoneinfo/Europe/Lisbon /etc/localtime, with -s for a symbolic link and -f to replace the link that is already there. What matters is that /etc/localtime must BE the zone data — a copy of the file or a link to it — and not the name of a zone. Writing the string Europe/Lisbon into /etc/localtime produces a file the C library cannot parse, which is a favourite distractor precisely because it is what /etc/timezone legitimately contains one directory along.
Worth carrying in
- LANG / LC_* / LC_ALL
- Fallback, per-category, and the override that beats both.
- LC_ALL=C
- Plain unlocalised behaviour — predictable sorting and formatting for scripts.
- locale -a
- Every locale installed.
- iconv -f -t
- Convert a file between character encodings.
- /etc/localtime
- The active time zone, from
/usr/share/zoneinfo/. - TZ=Europe/Berlin
- Override the time zone for one process.
- hwclock
- The firmware clock. date reads and sets the system clock.
- timedatectl set-timezone
- Time, zone and NTP state in one systemd command.
- ln -sf /usr/share/zoneinfo/… /etc/localtime
- Setting the zone without systemd. The file holds zone DATA, never a zone name.
- export LC_MESSAGES=C
- English messages while every other category keeps its locale.
What the exam does with this
LC_ALLwins over every LC_* variable, which win overLANG. Expect this as a precedence question.- UTF-8 is an encoding of Unicode, not a separate character set, and is ASCII-compatible for the first 128 characters.
- Keep the hardware clock in UTC. The time zone is a presentation layer on top of it.
- Objective
- 107. Administrative tasks
- Share of the exam
- 20% (the whole objective)
- Questions in this lesson
- 15
- Signed for by a person
- 0
Partly checked. None of the 15 questions here has been read against the cited source by a person. 15 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.
Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
Drill this lesson
A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.
Practise Locales, character encodings and time zones
Questions in this lesson
- Select the TWO true statements about locale environment variables. machine-checked
- On a systemd-based distribution, which command sets the system's time zone to Europe/Berlin, updating /etc/localtime accordingly? machine-checked
- Which statement correctly compares ASCII, ISO-8859-1 and UTF-8? machine-checked
- The file notes.txt is encoded in ISO-8859-1 and you want the converted UTF-8 text printed on standard output (not written to a file). Type the complete iconv command, using the exact charset names ISO-8859-1 and UTF-8. machine-checked
- A shell script that sorts a list of names produces one order on a developer's German desktop and a different order on the build server. The two machines differ only in their locale settings. Which locale category governs the order sort produces? machine-checked
- Before writing a conversion script you need to confirm that the local iconv installation knows the encoding named CP1252. Which command lists every encoding iconv can convert between? machine-checked
- Type the command, including the option, that prints the names of all locales that are available on the system. machine-checked
- A shared server is configured for UTC and must stay that way. One analyst wants every timestamp printed in her own shell session, and by the commands she starts from it, to appear in Tokyo local time. What should she do? machine-checked
- A machine with no working time synchronisation is running four minutes fast, and you must correct the system clock by hand to 2026-03-01 09:00:00. Which command does that? machine-checked
- You are fixing the time zone on a minimal system that has no systemd and no timedatectl. The machine must use Europe/Lisbon. Which action configures it correctly? machine-checked
- You are writing a provisioning script on a systemd host and need the exact spelling of the zone name for Auckland so you can grep for it. Which command prints the full list of valid time zone names to standard output? machine-checked
- Select the THREE true statements about time zone configuration on a Linux system. machine-checked
- Type the absolute path of the directory that holds the system's compiled time zone data files, from which /etc/localtime is taken. machine-checked
- Converting a UTF-8 address list to plain ASCII fails as soon as iconv meets a character such as e-acute. You want those characters approximated by similar ASCII ones, for example e, rather than dropped or fatal. Which command does that? machine-checked
- An administrator works on a host where LANG=de_DE.UTF-8. She wants command output and error messages in untranslated English so that she can search for them online, while keeping German number, date and currency formatting. Which environment setting achieves exactly that? machine-checked
Practise Locales, character encodings and time zones
The rest of objective 107
- User and group accounts
- Scheduling jobs to run unattended
- Locales, character encodings and time zones — you are here