Linux: Running a program with a different locale than your default

When your system is not running on English, you may sometimes want to run some applications and not use your system locale.
Use cases are scripts that parse output, or just using the (possibly) more common English labels or error messages. Here is how to do that.

I will use the date command and print the current weekday, just for the sake of an example.

Changing the locale using environment variables

Most often, setting LC_ALL for your command should be enough. The following was run on a system using a German locale.

$ date +%A

$ LC_ALL=C date +%A

C is usually fine to simply get English output (though there is more to it).

If LC_ALL does not work, try using LANG (if that still does not work, try LANGUAGE):

$ LANG=C date +%A

There are also other (more specific) environment variables, like LC_MESSAGES.
You can list them using the locale command.

Locale names

Note that you can only use locales that are actually available on your system.

Using LC_ALL=de will only work if there really is a "de" locale -- Ubuntu will not automagically guess something like de_DE.utf8.

Run locale -a to list all available locales.

To generate other locales, use the locale-gen command.

$ sudo locale-gen es_CR.utf8
Generating locales...
  es_CR.UTF-8... up-to-date
Generation complete.

$ LANG=es_CR.utf8 date +%A
Arne Hartherz over 6 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more