under Linux operation of files under Windows, often encountered garbled files, now is not know can not change the code of the Linux system, do not encode the file to convert
Here's a little information from yesterday.
If you need to operate files under Windows in Linux , you may often encounter problems with file encoding conversions. The default file format in Windows is GBK (gb2312), and Linux is generally UTF-8. Here's how to view the encoding of a file in Linux and how to encode and convert the file.
View File Encoding
There are several ways to view file encodings in Linux:
1. The file encoding can be viewed directly in Vim
: Set fileencoding
You can display the file encoding format.
If you just want to see other encoded files or if you want to solve the problem of viewing files garbled with Vim, you can
Add the following to the ~/.VIMRC file:
Set Encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936
This allows vim to automatically identify the file encoding (which automatically identifies the UTF-8 or GBK encoded file), in fact, in accordance with the fileencodings provided by the encoding list to try, if not found the appropriate encoding, the latin-1 (ASCII) encoding opened.
File Encoding Conversion
1. Convert file encoding directly into Vim, such as converting a file to Utf-8 format
: Set Fileencoding=utf-8
2. Iconv conversion, the ICONV command format is as follows:
Iconv-f ENCODING-T Encoding Inputfile
such as converting a UTF-8 encoded file into a GBK encoding.
Iconv-f gbk-t UTF-8 file1-o file2
Iconv-f gbk-t UTF8 Linux common commands. txt > Linux common commands. Txt.utf8
File name Encoding conversion:
From Linux to the Windows copy files or from Windows to Linux copy files, sometimes the Chinese file name garbled, the cause of this problem is because the Windows file name Chinese encoding defaults to GBK, and the default file name in Linux is encoded as UTF8, Because the encoding is inconsistent, so the file name garbled problem, to solve this problem need to transcode the file name.
A tool convmv for file name encoding is provided specifically in Linux, which converts the file name from GBK to UTF-8 encoding, or from UTF-8 to GBK.
First look at whether the CONVMV is installed on your system, if it is not installed:
Yum-y Install CONVMV
Installation.
Here's a look at the specific usage of CONVMV:
Convmv-f Source code-T new encoding [options] File name
Common parameters:
-R recursive processing of subfolders
--notest the actual operation, please note that by default, the file does not actually operate, but only the experiment.
--list display of all supported encodings
--unescap can be escaped, such as to turn%20 into a space
For example, we have a UTF8 encoded file name, converted to GBK encoding, the command is as follows:
Convmv-f UTF-8-T GBK--notest UTF8 encoded file name
after this conversion "UTF8 encoded file name" will be converted to GBK encoding (only the file name encoding conversion, the contents of the files will not change)
Why is it garbled to view files in. txt format under Linux? Because the Linux operating system and the Windows operating system are compressed differently for Chinese. In Windows, Chinese compression is generally. GBBK, and compressed into UTF8 in a Linux environment, which results in a garbled state of. txt files that are displayed correctly under Windows when they are opened in Linux. For this scenario, in the directory that contains the. txt file that you want to open, enter it in the terminal:
650) this.width=650; "src=" Http://blog.chinaunix.net/attachment/201302/23/27177626_1361615161YsfF.png "height=" 18 "Width=" 483 "/>
using the LS command view, generated a. UTF8 format file, at which point the file is no longer garbled . :
650) this.width=650; "src=" Http://blog.chinaunix.net/attachment/201302/23/27177626_1361615327Bngh.png "height=" 21 "Width=" 366 "/>
Linux solves garbled problems and view file encoding methods