If you find yourself as a network administrator or hacker penetration tester working with international clients and users, you will need to know how to localize Linux. Read on and Secur will teach you everything you ever wanted (and didn’t know you wanted) to know about how to localize Linux.
Linux Localization Basics
Since the construction of the Tower of Babel, the people of the world have communicated in different languages, resulting in each country having its own syntax for:
- Numerical values,
- Monetary values, and
- Time and date notation.
As such, it is important to know how to localize Linux and adapt it to the local language formatting; localization refers to the process of adapting Linux systems to a specific locale which involves identifying how to handle the characters contained in the local language.
Managing Character Sets In Linux
While as a super nerd, you might be able to walk, talk and think in binary just like an operating system, for the rest of us mere mortals, a computer needs to know how to speak an actual language, and this is where character sets come in. Character set defines the standard code to interpret and display language characters and while there many different character sets in use, the most common ones are:
- ASCII/The American Standard Code for Information Interchange: Uses 7 bits to store English language characters. For work in English-speaking countries, the UTF-8 character set is replacing ASCII as the standard.
- Unicode: Can represent every character known to be in use in all countries of the world with a 3-byte code and
- UTF/The Unicode Transformation Format (UTF): Transforms long Unicode values into either 1-byte (UTF-8) or 2-byte (UTF-16) simplified codes.
Once you’ve decided on a character set for your Linux system, you’ll need configure the Linux system to use it.
Linux Environmental Variables
Each of the “LC_” environment variables in the screenshot above represents a category of more environment variables related to the locale settings; the screenshot below explores the “LC_TELEPHONE” environment variable by using the -ck option. Administrators and developers can modify individual environment variables to control exactly how their programs behave within the locale.
Setting Your Locale in Linux
As demonstrated earlier in this article, there are three components to how Linux handles localization:
- The language,
- The country, and
- The character set the system uses.
You can modify each of these localization settings a number of ways
Locale Decisions Made During Installation
Changing the Localization of Your Linux System
If you want to modify localization values of installation of a Linux system, you can do it by either:
- Manually setting the LC_ environment variables: change individual LC_ localization environment variables by using the export command:
$ export LC_MONETARY=en_GB.UTF-8
While this works for changing individual settings, but it is not efficient to change all the system’s localization settings; the LANG environment variable is designed to control all of the other variables and you can use it like so:
$export LANG=en_GB.UTF-8
- Using the localectl command. Linux distribution with systemd utilities include the “localectl” command. By default, the localectl command just dis- plays the current localization settings, which you can see in the screenshot below. As you can see, the command shows the LANG environment variable setting, the keyboard layout mapping and X11 graphical environment layout. The command’s most common options are:
- list-locales: Lists all of the locales installed on your system
- set-locale: Offers an easy way to change the localization settings with the following command:
$ localectl set-locale LANG=en_GB.utf8
Managing Linux Time Settings
Your Linux system depends on proper operation of its date and time functions, as it uses them to:
- Track of running processes,
- Know when to start or stop jobs,
- Log important events that occur.
Linux handles the time as two parts:
- The time zone associated with the location of the system
- The actual time and date within that time zone.
Managing Time Zone Settings In Linux
Understanding time zones is essential to managing Linux time zone settings. If your Linux network has servers in different time zones, time zone settings are going to be important to you. Debian-based Linux systems set the local time zone in the “/etc/timezone” file, however as tthese files are not in a text format, do not you edit the “/etc/timezone” to modify your time zone. Rather, copy the template file stored in the “/usr/share/ zoneinfo” folder. As seen in the screenshot below, use the date command to determine your Linux system’s current time zone setting.
mv /etc/localtime /etc/localtime.bak # ln -s /usr/share/zoneinfo/US/Pacific /etc/localtime $dateIf want to change the time zone for a single session or program, rather than changing the system time zone, set the time zone using the TZ environment variable, overriding the system time zone for the current session.
Setting the Time and Date
Legacy Linux Time and Date Commands
There are two time/data management commands on almost all Linux distributions:
- hwclock: displays/sets the time from the internal BIOS or UEFI clock on the workstation or server.
- Provides access to the hardware clock built into the physical workstation/server running Linux.
- Use the command to set the system time and date to the hardware clock on the physical workstation or server.
- Allows you to change the hardware clock to match the time and date on the Linux system.
- date: a versatile command that displays or sets the date as kept by the Linux system.
- Allows you to display the time and date in a multitude of formats in addition to setting the time and/or date.
- You can set the time/date using the date command by specifying the value in the following format:
date MMDDhhmm[[CC]YY][.ss]
- The month, date, hour, and minute values are required, with the year and seconds assumed, or you can include the year and seconds as well if you prefer.
- The “+” option specifies the format used to display the time or date value by defining command sequences:
date +”%A, %B %d, %Y”
As you can see from the table below, the date command provides with numerous ways to display the time and date.
Sequence | Description |
---|---|
%a | Abbreviated weekday name |
%A | Full weekday name |
%b | Abbreviated month name |
%B | Full month name |
%c | Date and Time |
%C | Century |
%d | Numeric day of month |
%D | Full numeric date |
%e | Day of month, space padded |
%F | Full date in SQL format (YYYY-MM-dd) |
%g | Last two digits of year of ISO week number |
%G | Year of the ISO week number |
%h | Alias for %b |
%H | Hour in 24 hour format |
%I | Hour in 12 hour format |
%j | Numeric day of year |
%k | Hour in 24-hour format, space padded. |
%l | Hour in 12-hour format, space padded |
%m | Numeric month |
%M | Minute |
%n | A newline character |
%N | Nanoseconds |
%p | AM/PM |
%P | Lowercase am/pm |
%r | Full 12-hour clock time |
%R | Full 24-hour hour and minute |
%s | Seconds since 1970-01-01 00:00:00 UTC |
%S | Second |
%t | A tab character |
%T | Full time in hour:minute:second format |
%u | Numeric day of week, 1 is Monday |
%U | Numeric week number of year, starting on Sunday |
%V | ISO week number |
%w | Numeric day of week, 0 is Sunday |
%W | Week number of year, starting on Monday |
%x | Locale’s date representation as month/day/year or day/month/year |
%X | Locale’s full time representation |
%y | Last two digits of the year |
%Y | Full year |
%z | Time zone in +hhmm format |
%:z | Time zone in +hh:mm format |
%::z | Time zone in +hh:mm:ss format |
%:::z | Numeric time zone with : to necessary precision |
%Z | Alphabetic time zone abbreviation |
The timedatectl Command
If your Linux distribution has Systemd utilities, you can use the “timedatectl” command to manage the time/date settings. You can use the command to:
- See all th time information, including the hardware clock, called RTC, the date information, and the time zone information.
- Modify any of those settings with the set-time option:
timedatectl set-time “2018-10-06 10:35:00”
- Synchronize the workstation/server hardware clock and the Linux system time.
Monitoring Linux System Time
The time command displays the amount of time it takes for a program to run on the Linux system, as well as three additional lines of information (seen in the screenshot below):
- real: The elapsed amount of time between the start and end of the program
- user: The amount of user CPU time the program took
- sys: The amount of system CPU time the program took