How to Localize Linux

Share This Post:

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Linux localization

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

Linux stores locale information in the environment variables; programs needing to determine the locale of a Linux system to retrieve the appropriate environment variable to see what character set to use. The “locale” command to help you easily display these environment variables; the system in the screenshot below is localized to English and the United States. The output format of the locale command defines the localization information as: language_country.character set
Linux locale localization

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.

LC_telephone locale Linux

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

When you first install a Linux operating system, you are asked for the default system language; upon language selection, the installation process sets the localization environment variables appropriately for the country/language, including the character set required to represent the required characters. In many situations, this is all the Linux system localization you will do.

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
localectl command
Using the "localectl" command to display current localization settings.

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.

date command linux
In the image above, you see thatt time zone appears as the standard three-letter code at the end of the date/time/year display.  Changing the time zone for a Linux system, involves copying/linking the appropriate time zone template file from the “/usr/share/zoneinfo” folder to the “/etc/timezone” location. The /usr/share/zoneinfo folder is divided into subfolders based on location and each location folder may be subdivided into more detailed location folders;  drill down the file tree long enough, and eventually you’ll find a time zone template file associated for your specific time zone, such as “/usr/share/zoneinfo/Canada/Eastern“.  You’ll need to remove (move it and save it as a back up) the original timezone or localtime file before linking a new file:
mv /etc/localtime /etc/localtime.bak # ln -s /usr/share/zoneinfo/US/Pacific /etc/localtime $date
If 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

Once you figured out how to set correct time zone on your Linux system, you can set the correct time and date with a few different commands

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.

SequenceDescription
%aAbbreviated weekday name
%AFull weekday name
%bAbbreviated month name
%BFull month name
%cDate and Time
%CCentury
%d Numeric day of month
%D Full numeric date
%eDay of month, space padded
%FFull date in SQL format (YYYY-MM-dd)
%gLast two digits of year of ISO week number
%GYear of the ISO week number
%hAlias for %b
%H Hour in 24 hour format
%IHour in 12 hour format
%jNumeric day of year
%kHour in 24-hour format, space padded.
%lHour in 12-hour format, space padded
%mNumeric month
%MMinute
%nA newline character
%NNanoseconds
%pAM/PM
%PLowercase am/pm
%rFull 12-hour clock time
%RFull 24-hour hour and minute
%sSeconds since 1970-01-01 00:00:00 UTC
%SSecond
%tA tab character
%TFull time in hour:minute:second format
%uNumeric day of week, 1 is Monday
%UNumeric week number of year, starting on Sunday
%VISO week number
%wNumeric day of week, 0 is Sunday
%WWeek number of year, starting on Monday
%xLocale’s date representation as month/day/year or day/month/year
%XLocale’s full time representation
%yLast two digits of the year
%YFull year
%zTime zone in +hhmm format
%:zTime zone in +hh:mm format
%::zTime zone in +hh:mm:ss format
%:::zNumeric time zone with : to necessary precision
%ZAlphabetic 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.
timedatectl command
Using the "timedatectl" command.

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
time ls -la command
Using the time command to monitor the elapsed time associated with a program.

Share This Post:

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents

You May Like

Related Posts

Networking
Linux Administrator

How Does A DHCP Server Work?

Understanding How DHCP Works You’ve all had the experience of turning on your computer and it automatically connects to the network.  Understanding how a DHCP

Read More »
Linux meme
Linux Basics
Linux Administrator

Adding and Removing Linux Software

A fundamental task as system administrator is adding and removing Linux software that either didn’t come with the distribution or removing unwanted software to free

Read More »