Linux、Mac下GBK与UTF8编码文件的批量转换脚本
使用 iconv 进行批量转码
FILES=$(find . -type f -name '*.java')
for f in $FILES
do
if test -f $f; then
CHARSET="$( file --mime-encoding "$f"| awk -F ": " '{print $2}')"
if [ "$CHARSET" != utf-8 ]; then
sh -c "iconv -f $CHARSET -t UTF-8 $f > $f.temp"
mv -f "$f.temp" $f
fi
else
echo -e "\nSkipping $f - it's a regular file";
fi
done
终端运行
sh to.sh