How to get terminal's Character Encoding

2019-01-04 08:29发布

Now I change my gnome-terminal's character encoding to "GBK" (default it is UTF-8), but how can I get the value(character encoding) in my Linux?

标签: linux
5条回答
我命由我不由天
2楼-- · 2019-01-04 08:50

The terminal uses environment variables to determine which character set to use, therefore you can determine it by looking at those variables:

echo $LC_CTYPE

or

echo $LANG
查看更多
Root(大扎)
3楼-- · 2019-01-04 08:53

Check encoding and language:

$ echo $LC_CTYPE
ISO-8859-1
$ echo $LANG
pt_BR

Get all languages:

$ locale -a

Change to pt_PT.utf8:

$ export LC_ALL=pt_PT.utf8 
$ export LANG="$LC_ALL"
查看更多
叛逆
4楼-- · 2019-01-04 09:06

If you have Python:

python -c "import sys; print(sys.stdout.encoding)"
查看更多
我想做一个坏孩纸
5楼-- · 2019-01-04 09:10

To my knowledge, no.

Circumstantial indications from $LC_CTYPE, locale and such might seem alluring, but these are completely separated from the encoding the terminal application (actually an emulator) happens to be using when displaying characters on the screen.

They only way to detect encoding for sure is to output something only present in the encoding, e.g. ä, take a screenshot, analyze that image and check if the output character is correct.

So no, it's not possible, sadly.

查看更多
狗以群分
6楼-- · 2019-01-04 09:11

locale command with no arguments will print the values of all of the relevant environment variables except for LANGUAGE.

For current encoding:

locale charmap

For available locales:

locale -a

For available encodings:

locale -m
查看更多
登录 后发表回答