我正在使用这个脚本,但你必须指定你从哪个编码进行转换。如何使它自动检测当前的编码?
dir_iconv.sh
#!/bin/bash
ICONVBIN='/usr/bin/iconv' # path to iconv binary
if [ $# -lt 3 ]
then
echo "$0 dir from_charset to_charset"
exit
fi
for f in $1/*
do
if test -f $f
then
echo -e "\nConverting $f"
/bin/mv $f $f.old
$ICONVBIN -f $2 -t $3 $f.old > $f
else
echo -e "\nSkipping $f - not a regular file";
fi
done
终端命令行
sudo convert/dir_iconv.sh convert/books CURRENT_ENCODING utf8