linux 下命令编码转换

时间:2021-12-05 08:40:28
用 iconv , 没有就用 piconv,用法 iconv -f "gbk" -t "utf-8" < infile > outfile piconv -f "gbk" -t "utf-8" < infile > outfile 如果太多档案,写个 bash 脚本,放到要转换编码的目录 里,脚本这样 #! /bin/bash ICONV=iconv if ! which $ICONV &> /dev/null then ICONV=piconv fi for i in *Action.cpp do $ICONV -f "gbk" -t "utf-8" < "$i" > "$i.utf8" ret=$? if [ $ret -eq 0 ] ; then mv -f "$i" "$i.backup" mv -f "$i.utf8" "$i" else echo "fail to convert $i from gbk to utf-8" fi done exit $ret #end 这脚本会把你原来的gbk编码档案转换为 utf8 的新档案, 没测试, :)