Home  >  Article  >  Operation and Maintenance  >  Linux and windows files display garbled characters

Linux and windows files display garbled characters

王林
王林Original
2019-11-06 09:44:024063browse

Linux and windows files display garbled characters

Question:

Copy the code (.m) file written in matlab under Windows to Linux (Ubuntu), and the comments are in Chinese It's all gibberish.

Reason:

The default encoding under Windows is GB2312, and the default encoding under Linux is UTF-8. Therefore, the code generated under Windows is GB2312 encoding, which is of course recognized as garbled code under Linux; conversely, the code is garbled in the same way.

Solution:

Use the iconv command under linux to change the encoding of the file:

test1.m is converted from GB2312 to UTF-8 (windows The code of matlab under linux runs under linux)

iconv  -f  GB2312  -t  UTF-8  test1.m  -o  test1.m

test2.m is converted from UTF-8 to GB2312 (the code of matlab under linux runs under windows)

iconv -f  UTF-8  -t  GB2312  test2.m  -o  test2.m

Recommended tutorial: linux tutorial

The above is the detailed content of Linux and windows files display garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn