源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

批量转换目录下文件编码的shell脚本代码

  • 时间:2021-09-25 01:21 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:批量转换目录下文件编码的shell脚本代码
一例批量转换目录下文件编码的shell脚本代码。 需求描述: 由于从window转linux过来,很多原来win下的gbk文件需要转换成utf8。 以下脚本仅判断非utf8文件转换成utf8文件,并且默认非utf8文件为gbk,如果文件类型不一致需要修改。 例子:
[u]复制代码[/u] 代码如下:
#!/bin/bash # File Name: iconv.sh # Author: wanggy # site: www.1sucai.cn # show_file() {     for file in `ls $1`     do         if [ -d $1"/"$file ];then             #目录递归调用show_file函数             show_file $1"/"$file         else             #文件             echo $1"/"$file             file_type=`file $1"/"$file`             type=`echo $file_type |grep UTF-8`             if [ -z "$type" ];then                 echo "为空非utf-8编码,转换"                 iconv -f gbk -t utf8 $1"/"$file -o $1"/"$file             else                 echo "utf8编码不用转换"             fi         fi     done } path=./shell show_file $path
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部