ZoyaPatel

windows与Linux互传文件编码转换和换行符处理

SohaniSharma

编码转换

将windows文件转换成支持Linux文件的换行符号,使用Unix2dos,那么如何装换文件编码呢?

举例子

有一个文件使用Big5 编码,如何装换成UTF-8 编码呢?

iconv

 sboxes@osboxes ~/D/vmware-tools-distrib> iconv --help
 Usage: iconv [OPTION...] [FILE...]
 Convert encoding of given files from one encoding to another.
 
  Input/Output format specification:
   -f, --from-code=NAME       encoding of original text
   -t, --to-code=NAME         encoding for output
 
  Information:
   -l, --list                 list all known coded character sets
 
  Output control:
   -c                         omit invalid characters from output
   -o, --output=FILE         output file
   -s, --silent               suppress warnings
       --verbose             print progress information
 
   -?, --help                 Give this help list
       --usage               Give a short usage message
   -V, --version             Print program version
 
 Mandatory or optional arguments to long options are also mandatory or optional
 for any corresponding short options.
 
 For bug reporting instructions, please see:
 <https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs>

常用语法

 iconv -f [原来编码] -t [新编码] file -o newfile

查看字符编码

 file -i filename

换行符转换

当把DOS文件在Linux 上打开的时候,比如:使用命令 cat -A file 我们会发现DOS换行符 ^M$ ,也被称为CRLF两个符号。但是在Linux 上仅有LF一个符号表示换行符。

转换

Linux系统中,提供了命令支持两者之间的转换

 dos2unix -kn file newfile 
 unix2dos -kn file newfile
 #含义:保留修改时间,保留源文件,转换成newfile

这里的unix就是Linux的前身,所以这里是一脉想成的,Linux发展都深受到unixminix 的影响,所以有大量相似之处。

使用

在不同系统 Windows 和 Linux 上复制纯文本,就需要使用unix2dos 或者dos2unix 进行转换。不建议在 Windows 上编辑好了文件上传到 Linux上,会容易发生错误。

Ahmedabad
Kolkata
Hyderabad
后一页 Bangalore 前一页

Random Manga

Ads

نموذج الاتصال