有些时候,目录和文件上有空格,不太好
记录几个批量改名的命令
免得以后需要又要找
情况1
目录中有空格,目录的空格改为下划线dir="./"
find $dir -name "* *" -type d |
while read name; do
na=$(echo $name | sed 's/ /_/g')
mv "$name" $na
done
情况2
文件名是空格开头的,直接去掉开头的空格dir="./"
find $dir -name "* *" -type f|grep "\/ "|
while read name; do
na=$name
while [[ $(echo $na|grep "\/ ") ]]; do
na=$(echo $na|sed 's/\/ /\//')
done
mv "$name" $na
done
情况3
文件名中有空格,空格改为下划线(和情况一就改了个参数)dir="./"
find $dir -name "* *" -type f |
while read name; do
na=$(echo $name | sed 's/ /_/g')
mv "$name" $na
done
情况4
目录和文件名的空格都改成下划线dir="./"
find $dir -name "* *" |
while read name; do
na=$(echo $name | sed 's/ /_/g')
mv "$name" $na
done