DWQA QuestionsCategory: ServerHow to deal with Chinese random code under Linux?
Xijiang moon asked 1 month ago

I use Mousepad to open a TXT file containing Chinese characters under Linux, which will prompt me to choose the encoding. But when I use other editors (such as ReText) that do not know how to set the encoding, there will be chaos. How can I solve this problem?

3 Answers
Best Answer
TechliveZheng answered 1 month ago

Generally, scrambling is caused by the fact that Chinese files are encoded by GBK and UTF-8 is the system.Several options:I. temporarily modify environment variablesThe command line calls the editor and modifies the corresponding environment variables, such asLC_ALL=zh_CN.GBK ReText file2. Modify the default locale of the system to zh_CN.GBK3. Use iconv to convert file to UTF-8

iconv -f gbk -t utf-8 file.gbk > file.utf-8

4. Learn how to modify specific editor coding settings

TechliveZheng replied 1 month ago

It is not advisable to modify the system locale. After all, UTF-8 is the trend, so it is suggested that UTF-8 be converted to UTF-8, or some editors that can automatically recognize GBK codes, such as gedit, or find ways to modify the coding settings of the editor. I usually code it, but I rarely encounter GBK files now.

da_a answered 1 month ago

When the current encoding of a file is not clear, it can be used when it needs to be converted to a target encoding.encaIt automatically identifies the current encoding

jollywing answered 1 month ago

Don’t use mousepad. That editor is too simple.