One . Preparation
1. First, in the windows Open notepad in the environment , Then create a text file containing Chinese characters and English , Input content “ Test in windows The text edited in the notepad in
Pieces of , Upload to linux There will be no garbled code on the server ?test!”. The file named “ Test garbled files .txt”.
2. Use xftp Upload this file to linux The server , stay linux View content in context , The output is garbled .
[[email protected] ~]# cat Test garbled files .txt
²㋔՚windowsoµļȊ±¾o±༭µŎı¾τ¼þ£¬ʏ´«µ½linux·þϱǷʏ»»ᴶЖÒ룿
Two . Encoding conversion
1. The reason for this problem is a coding problem . We use iconv Code conversion .
#iconv The parameters are as follows :
-f, --from-code= name Original text encoding
-t, --to-code= Output encoding
-o, --output=FILE Output file name
-l, --list List all known character sets
#iconv The command format of is :iconv -f Original text encoding -t Output encoding The file name to be converted -o Converted file name
[[email protected] ~]# iconv -f gb2312 -t utf8 Test garbled files .txt -o aaa.txt
[[email protected] ~]# ls
201810240430234009.pcm apache-tomcat-8.0.51.tar.gz glibc-aarch64-linux-gnu-2.24-2.sdl7.2.noarch.rpm jdk-8u172-linux-x64.tar.gz qemu-2.11.0.tar.xz telnet-0.17-64.el7.x86_64.rpm
a busybox-1.24.2 glibc-aarch64-linux-gnu-devel-2.24-2.sdl7.2.noarch.rpm linux-4.19.77 qemu-4.1.0 test2.txt
aaa.txt busybox-1.24.2.tar.bz2 idea Shortcut key .txt linux-4.19.77.tar qemu-4.1.0.tar test.txt
anaconda-ks.cfg ceshi.txt iu.jpg nginx-1.8.0.tar.gz rootfs Test garbled files .txt
[[email protected] ~]# cat aaa.txt
Test in windows Text files edited in notepad in , Upload to linux There will be no garbled code on the server ?
# This command enumerates all known character sets
[[email protected] ~]# iconv -l
After the above operation , We have solved the problem of Chinese character garbled .