1. Command function
The encoding format used by icnov to convert files
There is no icnov file in linux by default, you need to install http://www.gnu.org/software/libiconv/ .
(1) Download libiconv package
[root@localhost ~]# wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
(2) Compile the source code
[root@localhost ~]# tar zxf libiconv-1.15.tar.gz #Unzip [root@localhost ~]# cd libiconv-1.15 [root@localhost libiconv-1.15]# ./configure --prefix=/usr/local [root@localhost libiconv-1.15]# make && make install ...... make[1]: Leaving directory `/root/libiconv-1.15/man'
Compilation is complete, the command can be used normally
2. Grammar format
iconv [OPTION...] [-f encoding] [-t encoding] [inputfile ...]
iconv options source encoding new encoding input file
Parameter Description
parameter |
Parameter Description |
-f encoding-A |
Convert from code A |
-t encoding-B |
Convert to code B |
-1 |
Display system supported encodings |
-O |
input output to the specified file |
3. Example of use
Windows-encoded files are uploaded to Linux, and the contents of the files cannot be displayed through the cat command.
[root@localhost ~]# cat windows_gb2312.txt ӭlinux world.
Check file encoding
Method 1 file filename
[root@localhost ~]# file windows.txt windows.txt: ISO-8859 text, with no line terminators
Method 2 Enter in vim filname: set
[root@localhost ~]# vim windows.txt #Open Chinese garbled characters :set fileencoding ÄãºÃ£¬»¶Ó´µ½linux world. ~ ::set fileencoding output: fileencoding = latin1
ps: latin1 is an alias for ISO-8859-1.
ISO-8859-1 encoding is a single-byte encoding, backward compatible with ASCII.