Linux、Mac下GBK与UTF8编码文件的批量转换 发表于 2017-10-10 更新于 2018-01-09 分类于 工具 使用 iconv 进行批量转码脚本工具 Linux、Mac下GBK与UTF8编码文件的批量转换脚本使用 iconv 进行批量转码 12345678910111213FILES=$(find . -type f -name '*.java')for f in $FILESdo 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"; fidone 终端运行 1sh to.sh