#!/bin/bash - #=============================================================================== # # FILE: rename.sh # # USAGE: ./rename.sh # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: linkscue (scue), linkscue@gmail.com # CREATED: 2013年04月03日 09时45分34秒 HKT # COPYRIGHT: Copyright (c) 2013, linkscue # REVISION: 0.1 # ORGANIZATION: ATX破晓组 #=============================================================================== if [[ $# == 0 ]]; then echo "使用方法: $(basename $0) <目录>"; echo "实现功能: 批量重命名含有空格的文件名"; exit 0 fi dir=$1 find $dir -type f | while read line; # 只显示文件 do array[i++]=\"$line\"; # 获取文件 echo ${array[i-1]}; # 为xargs准备 echo ${array[i-1]// /_} ; # 变量替换 # echo ${array[i-1]// -*.pdf/.pdf} | sed 's/\ /\_/g' ; # 变量替换(个人专用的) done | xargs -n 2 mv 2> /dev/null