LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 367|回复: 0

将文件名中的空格替换成一个下划线

[复制链接]
发表于 2012-3-15 16:32:38 | 显示全部楼层 |阅读模式
#!/bin/bash

# 名称:delspace.sh
# 功能:将文件名中的空格替换成一个下划线。
# 用法1、批量替换:find * -type d -exec /path/delspace.sh {} \;
# 用法2、替换当前目录:/path/delspace.sh ./

if test -z "$1"; then
        echo "String is null or empty"
else
        echo "$1"
        cd "$1"
        ls | while read i; do
                j=`echo $i|tr -s ' ' '_'`
                if test "$i" != "$j"; then
                        mv "$i" "$j"
                fi
        done
fi
---------------------------------------------------------------------
参考资料:
KornLee
===============================
ls|while read i;do
        mv "$i" $(echo $i|tr -d ' ') 2>/dev/null
done
===============================
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表