2011-02-11 29 views

回答

0

您并未真正提供有关文件名称的非常​​多信息。

假设你想要一大堆文件,并将它们从大写转换为小写,你可以做类似的事情。

rename.sh


#!/bin/bash 

# this script takes one argument, a filename. If the file doesn't exist, we die. 
# to accomodate files with spaces in the name, we'll grab $* as the filename. 

filename="$*" 

lowername=$(echo "$filename" | tr [A-Z] [a-z]) 

if [ ! -f $filename ]; then 
echo "File: $filename: file not found!" 
exit 1 
fi 

printf "%-70s" "Renaming $filename to $lowername: " 
st=$(mv "$filename" "$lowername" 2>&1) 
if (($? == 0)); then 
printf "%-8s\n" "[ ok ]" 
else 
printf "%-8s\n" "[ err ]" 
fi 

然后,您可以使用该脚本文件的目录树,或文件的一个子集,通过使用find命令。

find /some/directory/with/files -type f -name \*JPG -exec bash rename.sh {} \; 

现在,您可以修改“TR” ARGS,而“发现” args设置为自定义哪些文件获得改名重命名规则,以及它们是如何重新命名。

相关问题