By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Key Topics: Understanding Localization Setting Your Locale Looking at Time
Objective 1.7: Given a scenario, manage software configurations Linux has become a worldwide phenomenon. You'll find Linux desktops and servers all over the world, in many different kinds of environments. However, because of its worldwide popularity, Linux must support a wide variety of languages, date and time formats, and monetary formats. This guide walks through how to configure your Linux system to blend in with the local environment where it's running. First, this guide discusses how Linux handles different language characters, including how it formats monetary values. Then it moves on to how Linux handles times and dates as used in different countries. Understanding Localization The world is full of different languages. Not only does each country have its own language (or sometimes, sets of languages), each country has its own way for people to write numerical values, monetary values, and the time and date. For a Linux system to be useful in any specific location, it must adapt to the local way of doing all those things. Localization is the ability to adapt a Linux system to a specific locale. To accomplish this, the Linux system must have a way to identify how to handle the characters contained in the local language. The following sections discuss just how Linux does that. Character Sets At their core, computers work with ones and zeros, and Linux is no different. However, for a computer to interact with humans, it needs to know how to speak our language. This is where character sets come in. A character set defines a standard code used to interpret and display characters in a language. There are quite a few different character sets used in the world for representing characters. Here are the most common ones you'll run into (and the ones you'll see on the Linux+ exam): ASCII: The American Standard Code for Information Interchange (ASCII) uses 7 bits to store characters found in the English language. Unicode: An international standard that uses a 3-byte code and can represent every character known to be in use in all countries of the world. UTF: The Unicode Transformation Format (UTF), which transforms the long Unicode values into either 1-byte (UTF-8) or 2-byte (UTF-16) simplified codes. For work in English-speaking countries, the UTF-8 character set is replacing ASCII as the standard. Once you've decided on a character set for your Linux system, you'll need to know how to configure your Linux system to use it, which is shown in the following section. Environment Variables Linux stores locale information in a special set of environment variables. Programs that need to determine the locale of the Linux system just need to retrieve the appropriate environment variable to see what character set to use. Linux provides the locale command to help you easily display these environment variables. List: The Linux locale environment variables $ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.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= The output of the locale command defines the localization information in this format: language_country.character set In the example shown in List 9.1, the Linux system is configured for United States English, using the UTF-8 character set to store characters. Each LC_ environment variable itself represents a category of more environment variables that relate to the locale settings. You can explore the environment variables contained within a category by using the -ck option, along with the category name. List: The detailed settings for the LC_MONETARY localization category $ locale -ck LC_MONETARY LC_MONETARY int_curr_symbol="USD " currency_symbol="$" mon_decimal_point="." mon_thousands_sep="," mon_grouping=3;3 positive_sign="" negative_sign="-" . . . monetary-decimal-point-wc=46 monetary-thousands-sep-wc=44 monetary-codeset="UTF-8"
The environment variables shown in List 9.2 control what characters and formats are used for representing monetary values. Programmers can fine-tune each of the individual environment variables to customize exactly how their programs behave within the locale. Setting Your Locale As shown in the above List, there are three components to how Linux handles localization. A locale defines the language, the country, and the character set the system uses. Linux provides a few different ways for you to change each of these localization settings. Installation Locale Decisions When you first install the Linux operating system, one of the prompts available during the installation process is for the default system language. Figure below shows the prompt from a Rocky Linux 8 installation.
When you select a language from the menu, the Linux installation script automatically sets the localization environment variables appropriately for that country and language to include the character set necessary to represent the required characters. Often that's all you need to do to set up your Linux system to operate correctly in your locale. Changing Your Locale After you've already installed the Linux operating system, you can still change the localization values that the system uses. There are two methods available to do that. You can manually set the LC_ environment variables, or you can use the localectl command. Figure: The language option in a Rocky Linux 8 installation Manually Changing the Environment Variables For the manual method, change the individual LC_ localization environment variables just as you would any other environment variable, by using the export command: $ export LC_MONETARY=en_GB.UTF-8
That works well for changing individual settings, but it would be tedious if you wanted to change all the localization settings for the system.
Instead of having to change all of the LC_ environment variables individually, the LANG environment variable controls all of them at one place: $ export LANG=en_GB.UTF-8 $ locale
LANG=en_GB.UTF-8 LC_CTYPE="en_GB.UTF-8" LC_NUMERIC="en_GB.UTF-8" LC_TIME="en_GB.UTF-8" LC_COLLATE="en_GB.UTF-8" LC_MONETARY="en_GB.UTF-8" LC_MESSAGES="en_GB.UTF-8" LC_PAPER="en_GB.UTF-8" LC_NAME="en_GB.UTF-8" LC_ADDRESS="en_GB.UTF-8" LC_TELEPHONE="en_GB.UTF-8" LC_MEASUREMENT="en_GB.UTF-8" LC_IDENTIFICATION="en_GB.UTF-8"
Some Linux systems require that you also set the LC_ALL environment variable, so it's usually a good idea to set that along with the LANG environment variable. Tip: export command to the .bashrc file in your $HOME folder so that it runs each time you log in. The localectl command If you're using a Linux distribution that utilizes the systemd set of utilities, you have the localectl command available.
By default, the localectl command just displays the current localization settings: $ localectl
System Locale: LANG=en_US.UTF-8 VC Keymap: us X11 Layout: us Not only does it show the LANG environment variable setting, it also shows the keyboard layout mapping as well as the X11 graphical environment layout.
The localectl command supports many options, but the most common are to list all the locales installed on your system with the list-locales option and to change the localization by using the set-locale option: $ localectl set-locale LANG=en_GB.utf8 That makes for an easy way to change the localization settings for your entire Linux system. Looking at Time The date and time associated with a Linux system are crucial to the proper operation of the system. Linux uses the date and time to keep track of running processes, to know when to start or stop jobs, and in logging important events that occur. Having your Linux system coordinated with the correct time and date for your location is a must. Linux handles the time as two parts—the time zone associated with the location of the system and the actual time and date within that time zone. The following sections walk through how to change both values. Working with Time Zones One of the most important aspects of time is the time zone. Each country selects one or more time zones, or offsets from the standard Coordinated Universal Time (UTC) time, to determine time within the country. If your Linux environment includes having servers located in different time zones, knowing how to set the proper time zone is a must. Most Debian-based Linux systems define the local time zone in the /etc/timezone file, while most Red Hat–based Linux systems use /etc/localtime. These files are not in a text format, so you can't simply edit the /etc/timezone or /etc/localtime file to view or change your time zone. Instead, you must link that file to a template file stored in the /usr/share/zoneinfo folder. To determine the current time zone setting for your Linux system, use the date command, with no options: $ date Sat Dec 4 08:20:23 EST 2021 The time zone appears as the standard three-letter code at the end of the date and time display, before the year. To view the current time zone template file that the system is using, just use the ls command to display the active time zone file: $ ls -al /etc/localtime lrwxrwxrwx. 1 root root 38 Nov 30 09:06 /etc/localtime -> ../usr/share/zoneinfo/America/New_York
To change the time zone for a Linux system, link the appropriate time zone template file from the /usr/share/zoneinfo folder to the /etc/timezone or /etc/localtime location. The /usr/share/zoneinfo folder is divided into subfolders based on location. Each location folder may also be subdivided into more detailed location folders. Eventually, you'll see a time zone template file associated with your specific time zone, such as /usr/share/zoneinfo/US/Eastern. Before you can copy the new time zone file, you'll need to remove the original timezone or localtime file: $ sudo ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime $ date Sat Dec 4 07:23:14 CST 2021 The new time zone appears in the output from the date command. Note: TZ environment variable. That overrides the system time zone for the current session. Setting the Time and Date Once you have the correct time zone for your Linux system, you can work on setting the correct time and date values. There are a few different commands available to do that. Legacy Commands There are two legacy commands that you should be able to find in all Linux distributions for working with time and date values: hwclock displays or sets the time as kept on the internal BIOS or UEFI clock on the workstation or server. date displays or sets the date as kept by the Linux system.
The hwclock command provides access to the hardware clock built into the physical workstation or server that the Linux system runs on. You can use the hwclock command to set the system time and date to the hardware clock on the physical workstation or server. Or, it also allows you to change the hardware clock to match the time and date on the Linux system.
The date command is the Swiss Army knife of time and date commands. It allows you to display the time and date in a multitude of formats in addition to setting the time and/or date.
The + option allows you to specify the format used to display the time or date value by defining command sequences: $ date +"%A, %B %d, %Y" Saturday, December 04, 2021 TABLE: The date format command sequences
As you can see from the table above, the date command provides numerous ways for you to display the time and date in your programs and shell scripts. You can also set the time and 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 timedatectl Command If your Linux distribution uses the Systemd set of utilities You can use the timedatectl command to manage the time and date settings on your system: $ timedatectl
Local time: Sat 2021-12-04 08:27:18 EST Universal time: Sat 2021-12-04 13:27:18 UTC RTC time: Sat 2021-12-04 13:27:17 Time zone: America/New_York (EST, -0500) System clock synchronized: yes NTP service: active RTC in local TZ: no
The timedatectl command provides one-stop shopping to see all of the time information, including the hardware clock, called RTC, the date information, and the time zone information.
You can also use the timedatectl command to modify any of those settings as well by using the set-time option: # timedatectl set-time "2021-12-04 08:30:00" You can also use the timedatectl command to synchronize the workstation or server hardware clock and the Linux system time. The Network Time Protocol These days most Linux systems connected to the Internet utilize the Network Time Protocol (NTP) to keep the time and date synchronized with a centralized time server. If your Linux system does this, you won't be able to alter the time or date by using either the date or timedatectl command. Instead, you'll need to point your Linux server to an appropriate network time server.
There are three common NTP software implementations used in the Linux world: ntpd: Legacy software that uses the Simple Network Time Protocol (SNTP) to connect to a network time server chrony: An improved version of the ntpd software that utilizes security features timesyncd: Part of the Systemd startup utilities package that provides NTP services
The legacy ntpd software technically isn't supported anymore, but due to its simplicity a few Linux distributions still use it. Most Debian-based Linux distributions (including Ubuntu) use the Systemd startup utilities and thus utilize the timesyncd service to provide network time services. Although Red Hat–based systems also use Systemd, Red Hat has chosen to implement the more versatile chrony software to supply network time services.
Tip: timesyncd software stores its configuration settings in the /etc/systemd/timesyncd.conf file. If multiple configuration files are required, they are stored in the /etc/systemd/timesyncd.conf.d directory. The chrony software stores its configuration settings in the /etc/chrony/chrony.conf configuration file. Watching System Time The Linux+ exam also covers the time command, although it's not related to the time and date specifically. The time command displays the amount of time it takes for a program to run on the Linux system: $ time timedatectl
Local time: Sat 2021-12-04 08:40:40 EST Universal time: Sat 2021-12-04 13:40:40 UTC RTC time: Sat 2021-12-04 13:40:38 Time zone: America/New_York (EST, -0500) NTP service: active RTC in local TZ: no real 0m0.037s user 0m0.004s sys 0m0.006s After the normal command output, you'll see three additional lines of information: 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
This information can be invaluable when you're troubleshooting programs that seem to take additional system resources to process. The exercise below walks through using the different locale, time, and date functions you have available in Linux. EXERCISE: Experimenting with Time This exercise will demonstrate how to check the current time, date, and time zone on your Linux system. Type locale to display the current localization settings for your system. Write down the current character set assigned for your system. Change the localization to another country, such as Great Britain, by setting the LANG environment variable. Type export LANG=en_GB.UTF-8 to make the change. Type locale to display the updated localization settings. If your Linux distribution uses the Systemd utilities, type localectl to display the system localization defined on your system. Change the localization by typing localectl set-locale "LANG=en_GB_UTF-8". Change the localization back to your normal locale by using either the locale or the localectl command. Display the current date and time on your system by typing the date command. Observe how long it takes to run the date command on your Linux system by typing time date. The output shows how long it took your Linux system to process the request. The Linux system supports many different languages by incorporating different character sets. A character set defines how the Linux system displays and uses the characters contained in the language. While Linux supports many different character sets, the most common ones are ASCII, Unicode, UTF-8, and UTF-16. The ASCII character set is only useful for English language characters, whereas the UTF-8 and UTF-16 character sets are commonly used to support other languages. The Linux system maintains the character set settings as a set of environment variables that begin with LC_. The locale command displays all the localization environment variables. Each individual LC_ environment variable represents a category of other environment variables that fine-tune the localization settings even further. You can display those environment variable settings by adding the -ck option to the locale command. You change the individual LC_ environment variables by using the Linux export command. Instead of changing all the LC_ environment variables, you can set the special LANG or LC_ALL environment variable. Changing either of those variables will automatically change the other environment variables. Alternatively, if your Linux distribution supports the Systemd utilities, you can use the localectl command to display and change localization environment variable values. You must define a time zone for your Linux system. Debian-based Linux distributions use the /etc/timezone file to determine the system time zone, while Red Hat–based Linux distributions use the /etc/localtime file. Both files utilize a binary format, so you can't edit them directly. Linux maintains a library of time zone files in the /usr/share/zoneinfo folder. Just copy or link the appropriate time zone file from the /usr/share/zoneinfo folder to the time zone file for your Linux system.
There are three commands that you can use in Linux to display or change the time and date. The hwclock command displays the time as kept on the hardware clock for your Linux system. You can set the Linux system time to that or set the hardware clock to your Linux system time. The date command allows you to display the Linux system time and date in a multitude of formats by using a command-line sequence. It also allows you to set the date and time for the Linux system from the command line. For systems that use the Systemd utilities, the timedatectl command provides a single location to display all the system time and date information. The time command doesn't have anything to do with the current system time but instead provides information on the amount of time an individual application uses on the Linux system. You can use the time command to see how much real time elapsed between when the application started and when it finished as well as to display the amount of system or user CPU time it required. Important Exam Questions: 1. Describe how Linux works with different languages. - Linux stores and displays language characters by using character sets. ASCII, Unicode, and UTF-8 are the most commonly used character sets for Linux. 2. Explain how to change the current character set on a Linux system. - You can use the export command to change the LANG or LC_ALL environment variable to define a new character set. If your Linux distribution uses the Systemd utilities, you can also use the localectl command to display or change the system character set. 3. Describe how the time zone is set on a Linux system. - Time zones are defined in Linux by individual files in the /usr/share/zoneinfo folder. Debian-based Linux distributions copy the appropriate time zone file to the /etc/timezone file, whereas Red Hat–based Linux distributions use the /etc/localtime file. To change the time zone for an individual script or program, use the TZ environment variable. 4. Summarize the tools you have available to work with the time and date on a Linux system. - The hwclock command allows you to sync the Linux system time with the hardware clock on the system, or vice versa. The date command allows you to display the time and date in a multitude of formats or set the current time and date. The timedatectl command is from the Systemd utilities and allows you to display lots of different information about the system and hardware time and date in addition to allowing you to set them. 5. Describe how NTP works and how Linux systems use it. - The Network Time Protocol (NTP) allows Linux systems to synchronize their time and date from a centralized server across the network. There are three common software packages that implement NTP in Linux: the ntpd package, the chrony package, and the timesyncd program from the Systemd utilities. 6. Explain how you can see the amount of time it takes for an application to run on the system. - The time command allows you to place a timer on a specific application as it runs on the system. The output from the time command shows the actual elapsed time it took the program to run and how much user and system CPU time the application required.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.