Character Set of file conversion in Linux
For some reason, we often encounter garbled characters on Linux servers, which are caused by inconsistent Character Set codes of clients, servers, and files, here we will explain how to convert the character set of a file.
You can run the following command to convert the character set of a file:
Iconv-f {character set before conversion}-t {character set after conversion} inputfile-o outputfile
Note: If the-o parameter is not specified, iconv prints the file only on the plane, but does not change the character set attribute of the original file.
For example, to convert a file from UTF-8 to gb18030, run the following command:
Iconv-f UTF-8-t gb18030 a.txt-o B .txt
Of course, you can also write data to a new file through redirection.
Iconv-f UTF-8-t gb18030 a.txt> B .txt
You can also use the ls-l command to generate a batch conversion File Script, as shown below:
Ls-lrt | awk '{print "iconv-f UTF-8-t gb18030" $9 "-o" $9 ". new "}'
You can also use the find command in combination with xargs or-exec for direct conversion.
This article permanently updates the link address: