批量将目录下所有文件进行 dos/unix 格式转换

#批量转dos to unix (亲测可用!)

find . -name "*.sh" | xargs sed -i 's/\r$//g'
脚本方法二
#!/bin/bash

# File Name: iconv.sh
# Author: wanggy
# site: www.jbxue.com
#
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

标签: none

评论已关闭