Introduction
This lesson is about locale and language settings.
The main question is:
How do you make Linux use the right language, character encoding, date format, and timezone, and why does that matter in scripts?
What you should be able to do after this lesson:
- Understand
LANG,LC_*, andLC_ALL. - Inspect locale settings with
locale. - Understand UTF-8, ASCII, and legacy encodings at a beginner level.
- Configure timezone settings.
- Understand why
LANG=Ccan be useful in scripting.
Big Idea: Locale Settings Change How Text and Time Are Interpreted
Linux does not treat all text and formatting the same way automatically.
Locale settings affect things such as:
- language
- sort order
- date formatting
- month names
- character classification
That is why the same command output can look different on different systems.
LANG, LC_*, and LC_ALL
LANG
Default locale for the session.
LC_*
More specific category overrides, such as:
LC_TIMELC_MESSAGESLC_NUMERIC
LC_ALL
Strong override for all locale categories.
Simple beginner rule:
LANG= general defaultLC_*= category-specific overrideLC_ALL= strongest override
Inspect Locale Settings
locale
This command shows the current locale environment.
Why LANG=C Matters in Scripts
LANG=C forces a simple predictable locale.
Example:
LANG=C sort file.txt
Why scripts care:
- output becomes more predictable
- parsing text is easier when translated messages are not changing
This is one of the most practical LPIC ideas in this topic.
Character Encodings
ASCII
Very limited older character set.
UTF-8
Modern common encoding for Unicode text.
ISO-8859
Older family of encodings you may still see in legacy contexts.
Simple idea:
- UTF-8 is the modern normal case
- older encodings still matter when dealing with legacy data
iconv
iconv converts text from one encoding to another.
Example:
iconv -f ISO-8859-1 -t UTF-8 old.txt > new.txt
You do not need deep encoding theory here. You do need to know why text can look broken when encoding assumptions are wrong.
Timezone Settings
Common files and paths to recognize:
/etc/timezone
/etc/localtime
/usr/share/zoneinfo/
Helpful tools:
timedatectl
tzselect
date
Show current time settings
timedatectl
Choose a timezone interactively
tzselect
Environment Variable TZ
TZ can set timezone behavior for a process or shell session.
Example:
TZ=UTC date
This is useful for testing or scripting.
Practice Step by Step
1) Inspect the current locale
- Run:
locale - Look at:
LANG,LC_TIME,LC_MESSAGES, andLC_ALL
2) Force a predictable script locale
- Run:
LANG=C date - Read it as: run this command with a simple predictable locale.
3) Check timezone configuration
- Run:
timedatectl - Notice the current local time, timezone, and clock status.
Cheat Sheet
LANG= default localeLC_*= category-specific locale settingsLC_ALL= strongest locale overridelocale= show locale environmentLANG=C= simple predictable locale, useful in scripts- UTF-8 = modern common Unicode encoding
- ASCII, ISO-8859 = older encoding families to recognize
iconv= convert text encodings/etc/localtime,/usr/share/zoneinfo/= timezone-related pathstimedatectl,tzselect,date= timezone/time toolsTZ= per-process timezone override
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
