Solve the Problem of garbled characters in Chinese file names and file content transmitted to linux in windows.

Source: Internet
Author: User

Solve the Problem of garbled characters in the file name and content transmitted to linux in windows. Use winSCP to upload files in windows to linux. files containing Chinese characters will be garbled in linux, it can be set in the winscp environment. Coding problems frequently encountered in www.2cto.com linux if you need to operate files in windows in Linux, you may frequently encounter file encoding conversion problems. In Windows, the default file format is GBK (gb2312), while Linux is generally a UTF-8. Method 1: file filename Method 2: You can directly view the file encoding in Vim: set fileencoding if you only want to view files in other encoding formats or want to solve the problem of using Vim to View File garbled characters, you can go ~ /. Add the following content to the vimrc file: set encoding = UTF-8 fileencodings = ucs-bom, UTF-8, cp936, vim can automatically identify the file encoding (can automatically identify the UTF-8 or GBK encoding files), in fact, according to the fileencodings provided by the encoding list to try, if not find the appropriate encoding, use latin-1 (ASCII) encoding to open file encoding and conversion multi-platform method: iconv provides standard programs and APIs for encoding and conversion; convert_encoding.py is a Python-based text file conversion tool; decodeh. py provides algorithms and modules to talk about character encoding. in linux, file encoding conversion: Method 1: directly convert the file encoding in Vim, such as converting a file into UTF-8 format: set fileencoding = UTF-8 or 11) sets the file set, that is, the files to be operated on. Wildcards can be used. For example, I usually use the C/C ++ Source Program encoding and conversion: args *. h *. cpp 2) provides the command to be executed on each file. Here is the conversion code: argdo set fenc = UTF-8 | update Method 2: iconv conversion 5. case: If we upload a UTF-8 file under windows to linux, the system code in linux is GB18030, we will see garbled characters when cat, at this time we should think of transcoding, Next let's test: we will be a windows file named UTF-8.sh to the linux system, the content of the UTF-8.sh is as follows: I am a Chinese encoding UTF-8 mode ~ In linux, the system language is set: [root @ sor-sys zy] # cat/etc/sysconfig/i18n LANG = zh_CN.GB18030SYSFONT = "latarcyrheb-sun16" this time to view the file content and encoding: [root @ sor-sys zy] # file UTF-8.sh UTF-8.sh: UTF-8 Unicode text, with no line terminators [root @ sor-sys zy ~ [Root @ sor-sys zy] # [root @ sor-sys zy] # at this time, we need to convert the encoding, remember to use iconv [root @ sor-sys zy] # iconv-f UTF-8-t GB18030 UTF-8.sh-o GB18030.sh [root @ sor-sys zy] # cat GB18030.sh ?? I am a Chinese encoding UTF-8 mode ~ [Root @ sor-sys zy] # [root @ sor-sys zy] # file GB18030.sh GB18030.sh: Non-ISO extended-ASCII text, with no line terminators [root @ sor-sys zy] # convmv is a tool used to change the file name encoding method. For example, sudo convmv-f gbk-t UTF-8-r-notest/home changes all the original file names in the/home directory in the gbk encoding mode to the UTF-8 format. Here-f is followed by the original encoding method,-t is followed by the encoding method to be changed,-r indicates all the files under this directory, and-notest indicates immediate execution, instead of just testing. In addition, this command seems to have to be executed by root, so sudo should be added.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.