您现在的位置是:网站首页> 编程资料编程资料
批量转换目录下文件编码的shell脚本代码_linux shell_
2023-05-26
325人已围观
简介 批量转换目录下文件编码的shell脚本代码_linux shell_
一例批量转换目录下文件编码的shell脚本代码。
需求描述:
由于从window转linux过来,很多原来win下的gbk文件需要转换成utf8。
以下脚本仅判断非utf8文件转换成utf8文件,并且默认非utf8文件为gbk,如果文件类型不一致需要修改。
例子:
复制代码 代码如下:
#!/bin/bash
# File Name: iconv.sh
# Author: wanggy
# site: www.jb51.net
#
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
您可能感兴趣的文章:
相关内容
- linux Nginx 日志脚本_linux shell_
- 最快捷登陆ssh 服务器的方法_linux shell_
- shell脚本中echo显示内容带颜色的实现方法_linux shell_
- shell监控脚本 准备工作分享_linux shell_
- shell监控脚本实例—监控mysql主从复制_linux shell_
- 用于检测进程的shell脚本代码小结_linux shell_
- linux修改目录和文件权限的简单命令解释_linux shell_
- linux生成(加载)动态库静态库和加载示例方法_linux shell_
- 如何编写健壮的Bash脚本(经验分享)_linux shell_
- linux下保留文件系统下剩余指定数目文件的shell脚本_linux shell_
