Linux、Mac下GBK与UTF8编码文件的批量转换

使用 iconv 进行批量转码脚本工具

Linux、Mac下GBK与UTF8编码文件的批量转换脚本

使用 iconv 进行批量转码

1
2
3
4
5
6
7
8
9
10
11
12
13
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

终端运行

1
sh to.sh
0%