iconv命令:
Convert encoding of given files from one encoding to another,更改文件的编码格式
语法格式:
iconv -f encoding -t encoding inputfile
常用选项:
-f encoding :把字符从encoding编码开始转换
-t encoding :把字符转换到encoding编码
-l 列出已知的编码字符集合
-o file :指定输出文件
-c :忽略输出的非法字符
-s :禁止警告信息,但不是错误信息
实例:
[root@www1 ~]# iconv test.txt -f UTF-8 -t gbk ▒▒һ▒▒ ▒ڶ▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ You have mail in /var/spool/mail/root [root@www1 ~]# iconv test.txt -c -f UTF-8 -t gbk ▒▒һ▒▒ ▒ڶ▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ [root@www1 ~]# iconv test.txt -c -f UTF-8 -t gbk -o testt.txt You have mail in /var/spool/mail/root [root@www1 ~]# cat testt.txt ▒▒һ▒▒ ▒ڶ▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ [root@www ~]# cat dos2.txt ▒▒▒▒▒ٶȿ▒▒▒▒▒▒ٶȿ▒▒▒ ▒▒▒▒▒▒Ʒ▒▒˹▒ƴ▒▒▒ ▒ռ▒▒▒▒Ƽ▒▒▒ʦ▒▒ ▒ռ▒▒ط▒▒▒▒ʱ▒▒η▒▒ʢ [root@www ~]# iconv dos21.txt -f gbk -t UTF-8 发了速度快解放了速度快解放 放声大哭会计法拉斯科大姐夫 空间大福利科技大师傅 收集地方拉卡时间段法拉盛