Tuesday, January 3, 2023
HomeNetworkingUtilizing the Linux locale command

Utilizing the Linux locale command


The locale settings in Linux methods assist make sure that info like dates and occasions are displayed in a format that is smart within the context of the place you reside and what language you converse. Here is use them.

NOTE: Not one of the instructions described on this submit will change your locale settings. Some merely use a unique locale setting to show the response you is perhaps seeing from a unique location.

Listing your settings

If you happen to’re within the US, it is best to see one thing like this if you use the locale command to checklist your settings:

$ 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 en_US.UTF-8 settings within the above output all characterize US English. If you happen to’re in France, this response is extra probably:

LANG=fr_FR.utf-8
LC_CTYPE="fr_FR.utf8"
LC_NUMERIC="fr_FR.utf8"
LC_TIME="fr_FR.utf8"
LC_COLLATE="fr_FR.utf8"
LC_MONETARY="fr_FR.utf8"
LC_MESSAGES="fr_FR.utf8"
LC_PAPER="fr_FR.utf8"
LC_NAME="fr_FR.utf8"
LC_ADDRESS="fr_FR.utf8"
LC_TELEPHONE="fr_FR.utf8"
LC_MEASUREMENT="fr_FR.utf8"
LC_IDENTIFICATION="fr_FR.utf8"
LC_ALL=fr_FR.utf8

A whole bunch of traces of output will likely be displayed in the event you use the locale -a (checklist all locales) command because it lists locales from across the globe.

$ locale -a | wc -l
869

Right here’s a pattern:

$ locale -a | column | head -10
aa_DJ                   es_CO.iso88591          ms_MY.utf8
aa_DJ.iso88591          es_CO.utf8              mt_MT
aa_DJ.utf8              es_CR                   mt_MT.iso88593
aa_ER                   es_CR.iso88591          mt_MT.utf8
aa_ER@saaho             es_CR.utf8              my_MM
aa_ER.utf8              es_CU                   my_MM.utf8
aa_ER.utf8@saaho        es_CU.utf8              nan_TW
aa_ET                   es_DO                   nan_TW@latin
aa_ET.utf8              es_DO.iso88591          nan_TW.utf8
af_ZA                   es_DO.utf8              nan_TW.utf8@latin

Just like the en_US settings proven above, these codes, stand for the language and county (e.g., aa_DJ stands for Afar, Djibouti). You’ll be able to show an entire checklist with a command like the next that selects the parts on traces previous to the durations and limits the output to one among every earlier than organizing the itemizing in columns:

$ locale -a | grep "." | awk -F. '{print $1}' | uniq | column
aa_DJ           ca_FR           es_DO           is_IS           nhn_MX          st_ZA
aa_ER           ca_IT           es_EC           it_CH           niu_NU          sv_FI
aa_ET           ce_RU           es_ES           it_IT           niu_NZ          sv_SE
af_ZA           chr_US          es_GT           iu_CA           nl_AW           sw_KE
agr_PE          ckb_IQ          es_HN           ja_JP           nl_BE           sw_TZ
ak_GH           cmn_TW          es_MX           japanese        nl_NL           szl_PL
am_ET           crh_UA          es_NI           kab_DZ          nn_NO           ta_IN
an_ES           csb_PL          es_PA           ka_GE           no_NO           ta_LK
anp_IN          cs_CZ           es_PE           kk_KZ           nr_ZA           tcy_IN
ar_AE           C               es_PR           kl_GL           nso_ZA          te_IN
ar_BH           cv_RU           es_PY           km_KH           oc_FR           tg_TJ
ar_DZ           cy_GB           es_SV           kn_IN           om_ET           the_NP
ar_EG           da_DK           es_US           kok_IN          om_KE           th_TH
ar_IN           de_AT           es_UY           ko_KR           or_IN           ti_ER
ar_IQ           de_BE           es_VE           korean          os_RU           ti_ET
ar_JO           de_CH           et_EE           ks_IN           pa_IN           tig_ER
ar_KW           de_DE           eu_ES           ku_TR           pap_AW          tk_TM
ar_LB           de_IT           fa_IR           kw_GB           pap_CW          tl_PH
ar_LY           de_LI           ff_SN           ky_KG           pa_PK           tn_ZA
ar_MA           de_LU           fi_FI           lb_LU           pl_PL           to_TO
ar_OM           doi_IN          fil_PH          lg_UG           ps_AF           tpi_PG
ar_QA           dsb_DE          fo_FO           li_BE           pt_BR           tr_CY
ar_SA           dv_MV           fr_BE           lij_IT          pt_PT           tr_TR
ar_SD           dz_BT           fr_CA           li_NL           quz_PE          ts_ZA
ar_SS           el_CY           fr_CH           ln_CD           raj_IN          tt_RU
ar_SY           el_GR           fr_FR           lo_LA           ro_RO           ug_CN
ar_TN           en_AG           fr_LU           lt_LT           ru_RU           uk_UA
ar_YE           en_AU           fur_IT          lv_LV           ru_UA           unm_US
as_IN           en_BW           fy_DE           lzh_TW          rw_RW           ur_IN
ast_ES          en_CA           fy_NL           mag_IN          sah_RU          ur_PK
ayc_PE          en_DK           ga_IE           mai_IN          sa_IN           uz_UZ
az_AZ           en_GB           gd_GB           mai_NP          sat_IN          ve_ZA
az_IR           en_HK           gez_ER          mfe_MU          sc_IT           vi_VN
be_BY           en_IE           gez_ET          mg_MG           sd_IN           wa_BE
bem_ZM          en_IL           gl_ES           mhr_RU          se_NO           wae_CH
ber_DZ          en_IN           gu_IN           mi_NZ           sgs_LT          wal_ET
ber_MA          en_NG           gv_GB           miq_NI          shn_MM          wo_SN
bg_BG           en_NZ           hak_TW          mjw_IN          shs_CA          xh_ZA
bhb_IN          en_PH           ha_NG           mk_MK           sid_ET          yi_US
bho_IN          en_SC           he_IL           ml_IN           si_LK           yo_NG
bho_NP          en_SG           hif_FJ          mni_IN          sk_SK           yue_HK
bi_VU           en_US           hi_IN           mn_MN           sl_SI           yuw_PG
bn_BD           en_ZA           hne_IN          mnw_MM          sm_WS           zh_CN
bn_IN           en_ZM           hr_HR           mr_IN           so_DJ           zh_HK
bo_CN           en_ZW           hsb_DE          ms_MY           so_ET           zh_SG
bo_IN           eo              ht_HT           mt_MT           so_KE           zh_TW
br_FR           es_AR           hu_HU           my_MM           so_SO           zu_ZA
brx_IN          es_BO           hy_AM           nan_TW          sq_AL
bs_BA           es_CL           ia_FR           nb_NO           sq_MK
byn_ER          es_CO           id_ID           nds_DE          sr_ME
ca_AD           es_CR           ig_NG           nds_NL          sr_RS
ca_ES           es_CU           ik_CA           ne_NP           ss_ZA

Discover that solely 4 of the codes don’t use two-part naming: “C” for the POSIX standards-compliant format, “eo” for “esperanto” (the world’s most generally spoken constructed worldwide auxiliary language), Japanese and Korean .

Viewing  and looping via months and days

I found not too long ago that I the locale command can show the months of the yr or the times of the week with instructions like these:

$ locale mon
January;February;March;April;Could;June;July;August;September;October;November;December
$ locale day
Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday

The above instructions make looping via the months of the yr or the times of the week surprisingly simple. For instance, to loop via the months, use a command like this:

$ months=`locale mon | sed 's/;/ /g'`  <== flip semicolons into blanks
$ for mo in $months
> do
>   echo $mo
> achieved
January
February
March
April
Could
June
July
August
September
October
November
December

To loop via the times of the week, do that:

$ weekdays=`locale day | sed 's/;/ /g'`
$ for day in $weekdays
> do
>   echo $day
> achieved
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

Change the lauguage used for months and days

You may as well use a locale setting to show the months of the yr or the times of the week in another language. For instance, to show the months in French, use a command like this one:

$ LC_ALL=fr_FR.utf8 locale mon
janvier;février;mars;avril;mai;juin;juillet;août;septembre;octobre;novembre;décembre

To see the months in Swahili as an alternative, do that:

$ LC_ALL=sw_TZ.utf8 locale mon
Januari;Februari;Machi;Aprili;Mei;Juni;Julai;Agosti;Septemba;Oktoba;Novemba;Desemba

To checklist the present date and time in Russian and Italian, use instructions like these:

$ LC_ALL=os_RU.utf8 date
Крс 02 Янв 2023 11:35:31 EST $ LC_ALL=it_IT.utf8 date dom 3 gen 2023, 16:29:10, EST

Wrap-Up

Your locale settings are in place to make sure that date, time, and associated particulars are displayed within the format that is smart to you. They will, as described on this submit, additionally permit you to generate month-of-year and day-of-week loops and to show date/time info in different languages.

Copyright © 2023 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments