The course is part of this learning path
In this brief course - the third of six covering the LPIC-1 102 exam and the eighth of eleven courses making up the full LPIC-1 series - we will work with some key areas of Linux administration: managing users and groups, scheduling the execution of unattended tasks, and maintaining accurate and efficient system environment variables and localisation.
If you have thoughts or suggestions for this course, please contact Cloud Academy at firstname.lastname@example.org.
Whether you are responsible for an application server hosting Internet services or a PC designed for local use, part of your job as an administrator is to make sure your system settings are appropriate for your users and geographic location. In this video, we're going to learn how to identify and manage your system time zone settings and how to make sure your environment variables known as your locale properly reflect your needs.
Managing system time zones in Linux
We'll start with your time zone settings. Your current system time zone is stored in the /etc/timezone file. In my case, I'm in the American region, and within that, Toronto. You can also see that by running the date command, which displays the full current date and time. All the data for all available timezone is stored in the user share zone info directory. You can CD into the particular region, like America in my case, and find the file matching your zone. If the time zone setting is wrong or if your trans-continental flight is just landing and you want to keep your laptop in the loop, you can update it by creating a symbolic link linking the /etc/localtime file to the appropriate file in this directory. In my case, it would look like this. Alternatively, you can run tzselect and work through the menus to select your location. There's currently a bug affecting the tzselect on some systems. The alternative is to run sudo dpkg-reconfigure tzdata to have the same effect. A third method is to directly edit the /etc/timezone file. The LPI-C wants you to know about the time date CTL program, which controls time and time zone settings for Linux distributions running system D. As you can see, time date CTL by itself will display some useful information. You should be aware, however, that not all timedatectl features - like set-time or set-timezone - will necessarily work on all systems. If timedatectl isn't available by default on your computer, you can install it to Debian-based systems like Ubuntu and Mint, using apt-get install systemd-services.
To review, the /etc/timezone file contains your current time zone setting files in the user share zone info directory or present all available time zone locations. You can set the value of your /etc/localtime file by linking to it from a file and user share zone info, or you can set your zone using tzselect. timedatectl manages time zones for systemd machines.
Managing Linux system locales
Now let's look at system locales. Where you live in a world, will often determine how you visually represent all kinds of things, including the way you spell certain words, display dates in short form, or even numbers in currency so that your system software should be able to more effectively respond to your specific needs. Linux needs to set environment variables either globally or for specific use categories. To list your current environment variables, you can run locale. The first value is LANG, L-A-N-G, which when populated, will override all other values. In my case, the language of LANG is set to English, the country to Canada, CA, and the character encoding is UTF 8.
Currency, numbers including decimals and dates will all be displayed according to Canadian standards, whatever those are. I believe that the default paper size of LC underscore paper refers to letter format, which is slightly different than the A4 size popular in Europe. LC measurement would refer to Canada's metric system as opposed to various versions of imperial units. By the way, there are a number of alternative character encoding settings besides UTF 8, including ISO 8859 and the very simple but absolutely reliable ASCII. Locale -a will display all available locale settings. Using C as a value for LANG can be very useful in some server scripting environments as it provides an environment that's very compatible with syntax from the C programming language, the language with which most operating systems were written.
That pretty much takes care of identifying the values you've got right now, but we'll also need to know how to change them. Environment values are kept in the user bin locale file. But since that's a binary file, they can't be edited. You could use export to set a particular value for this shell session only. However, once you log out or reboot, you'll find yourself back to your original default. One way to change the default value is to edit the locale file that's in the /etc/default directory.
Let's review. The locale command will display your current local settings. The LANG equals value, if populated, will override all other locale values. LANG equals C will set your environment to emulate the C language as closely as possible. Export will change your locale settings for the session, and the contents of /etc/default locale determines the system default values.
While we're on the topic of locale, there's a very annoying bug I've noticed when running an Ubuntu virtual machine instance on Amazon's AWS. While executing certain operations like package management, you sometimes face a locale cannot set LC all to default locale, no such file or directory error. This won't usually be a big deal, that it can be easily resolved although I can't understand why it happens in the first place. To fix the problem, first make sure that the locale you'd like to use is available by running locale gen. Then edit the /etc/environment file so that it includes an LC all equals line with your particular locale choice.
About the Author
David taught high school for twenty years, worked as a Linux system administrator for five years, and has been writing since he could hold a crayon between his fingers. His childhood bedroom wall has since been repainted.
Having worked directly with all kinds of technology, David derives great pleasure from completing projects that draw on as many tools from his toolkit as possible.
Besides being a Linux system administrator with a strong focus on virtualization and security tools, David writes technical documentation and user guides, and creates technology training videos.
His favorite technology tool is the one that should be just about ready for release tomorrow. Or Thursday.