linux 批量转换文本编码为UTF-8

时间:2022-05-29 14:06:47
widon@widon-X401A:~/c++/boost/test/BoostTest$ cat ~/.bin/conv2utf-8.sh
if [ $# != 1 ]; then
    echo "Usage: conv2utf-8.sh FOLDERNAME"
    echo "Eg: conv2utf-8.sh ."
fi
find $1 -type f -exec enca -x utf-8 {} \;

一个简单的脚本,使用enca工具不需要指定文件原来的编码


widon@widon-X401A:~/c++/boost/test/BoostTest$ file *
base.h:                                              C++ source, ISO-8859 text, with CRLF line terminators
main.cpp:                                            C source, ISO-8859 text, with CRLF line terminators

widon@widon-X401A:~/c++/boost/test/BoostTest$ conv2utf-8.sh .
widon@widon-X401A:~/c++/boost/test/BoostTest$ file *
base.h:                                              C++ source, UTF-8 Unicode text
main.cpp:                                            C source, UTF-8 Unicode text


转换成功