how to change encoding for batch of files in linux

假设需要将所有 a 目录下的php文件,编码从gb2312转到utf8

cd a
find ./ -type f -name "*.php"|while read line;do
echo $line
iconv -f GB2312 -t UTF-8 $line > ${line}.utf8
mv $line ${line}.gb2312
mv ${line}.utf8 $line
done 

上面脚本将当前a目录下的所有php文件,从gb2312转到utf8,原文保存为*.php.gb2312。
如果需要删除原来的gb2312文件,只需执行:

find ./ -type f -name "*.utf8" -exec rm -f {} \;

猜你喜欢

转载自wuchengyi.iteye.com/blog/870562