【发布时间】:2025-11-22 23:25:02
【问题描述】:
我正在尝试将 iconv 指向一个目录,无论当前编码如何,所有文件都将转换为 UTF-8
我正在使用这个脚本,但您必须指定您要使用的编码。如何让它自动检测当前的编码?
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
【问题讨论】:
标签: linux ubuntu encoding utf-8 iconv