From the course: LPIC-1 Exam 102 (Version 5.0) Cert Prep

Configure locale settings and environment variables - Linux Tutorial

From the course: LPIC-1 Exam 102 (Version 5.0) Cert Prep

Start my 1-month free trial

Configure locale settings and environment variables

- [Instructor] Setting the locale from the GUI is fairly easy. Go to Applications, System Tools, Settings, and click on Region and Language. Let's talk about locale settings for a moment. The process of changing locale settings from the command line on the Linux OS that uses System D is very similar to changing time and date settings, except we're using the localectl command. Let's close the Region and Language dialog and open the Terminal. Application's favorites and click on Terminal. I'm going to make my Terminal fullscreen and zoom my font. Type in localectl and hit Enter. Localetcl shows us our language and keyboard keymap. To list our languages, use list locales. Type in localectl list dash locales and hit Enter. Now there's over 800 locales so we can narrow it down using grep. Press Q to quit. Localectl space list dash locales, and let's pipe this to grep. And let's find lines that begin with en. So we're going to type in grep space caret en and hit Enter. The locale I'm going to change to is en underscore US dot utf8. So the whole line should say, localectl, space, set dash locale, space, LANG equals en underscore US dot utf, hit Enter. We can verify this by typing in localectl again. To list other keymaps, use the list dash keymaps option. Localesctl list dash keymaps, hit Enter. Again, there's over 500 keymaps here so we'll use grep again to narrow it down. So the line should say localectl space list dash keymaps, space pipe, space grep space caret US, and hit Enter. Now we've narrowed it down substantially. I'm going to change my keymap to US. Localectl set dash keymap, space US and hit Enter. Now we've been able to change our locale and our keymap. Another tool that's very useful concerning date and time is the date command. Type in date, and it'll show you the current date and time. By default, the date command displays the local date and time. If we want to display Universal Time, we can pass the dash dash utc option. Type in date dash dash utc and hit Enter. If you're using a virtual machine like me, don't be alarmed if your date and time isn't correct. It all depends on how the date and time is getting passed to the virtual machine from VirtualBox. If you want to change the output format of the date command, you can with other options. For instance, if we wanted to show the month by abbreviation followed by the day in long year, I'm going to type in clear to clear my screen. And I'm going to type in date, the plus sign, double quote, percent, h, space, percent, d, space, percent, capital Y, and then another double quote and hit Enter. The syntax is date plus, and then inside double quotes, the parameters necessary. If you wanted to, check the man page for other options. Here's another example. Date, plus, double quote, percent, s, double quote and hit Enter. This is the number of seconds from January 1st 1970. We would do this whenever we wanted to calculate time such as in a script. We would get the current time in seconds, run the operation, get the time again and subtract the difference. Date can also take the number of seconds and output a date in whatever format we want. As an example, let's take the number of seconds in last operation and find the date for it. Type in date, space, dash dash date, equals, and then inside single quotes, the @ symbol, and the number that was the result of the command previous. I'll paste that in there, another single quote, and hit Enter, and it returns a date back. This comes in very handy if you ever want to calculate dates. For instance, let's say it's February 26th and we want to calculate 10 days in the future. You could type in date, space, dash dash date, space, inside single quotes, plus 10 days, another single quote and hit Enter. And it'll calculate 10 days for you. It also accepts more abstract wording, date, dash dash date, single quote, next Thursday, single quote, and hit Enter. There's a lot more that the date command can do so check out the man page for more options. There's one more time and date tool I'd like to show. Cal, hit Enter. Cal shows you a calendar. It seems silly at first, but it's actually quite useful. If you wanted to show three months, we can type in cal dash three and hit Enter, and it shows us three months. Note that this is different than typing in cal space three, which is the year number three. You can show the calendar for any year. For instance, cal 1752 and hit Enter. Notice anything strange about September. I'll leave that up to the viewer to research it.

Contents