linux与windows下文件编码问题

注:转换操作均在Linux终端进行操作

DOS与Unix格式转换

安装工具:dos2unixunix2dos

# ubuntu
apt-get install dos2unix
apt-get install unix2dos
# centos
yum -y install ···

DOS格式转换为Unix格式

单个文件

dos2unix <filename>

多个文件(在文件夹下执行)

find -type f | xargs dos2unix -o

Unix格式转换为DOS格式

单个文件

unix2dos <filename>

多个文件(在文件夹下执行)

find -type f | xargs unix2dos -o  

gbk与UTF-8编码转换

转换gbk编码文件为utf-8编码文件

iconv -f gbk -t utf-8 in_filename.csv > out_filename.csv

转换gbk编码文件为utf-8编码文件

iconv -c --verbose  -f gbk -t utf-8 in_filename.csv -o out_filename.csv

转换utf-8编码文件为gb2312编码文件

iconv -c --verbose  -f utf-8 -t gb2312 in_filename.csv -o out_filename.csv

查看文件当前编码

file -i filename
原文地址:https://www.cnblogs.com/chuyiwang/p/13823551.html