使用注意項:
原來文件格式gbk的,否則可能出現utf-8轉utf-8亂碼。
#!/bin/bash function gbk2utf(){ file="$1" echo "處理文件 '$file' ..." iconv -f gb2312 -t UTF-8 -c "$file" > tmp mv -f tmp "$file" } function getdir(){ for element in `ls $1` do dir_or_file=$1"/"$element echo $dir_or_file if [ -d $dir_or_file ] then getdir $dir_or_file else gbk2utf $dir_or_file fi done } getdir $1
運行:sh gbk2utf.sh dir
轉自:https://blog.csdn.net/pangyemeng/article/details/74315869
