find . -name "* *"|
while read name;do
na=$(echo $name | tr ' ' '_')
mv "$name" $na
done
tr命令:translation命令,用法:
tr [OPTION]... SET1 [SET2]
用set2来替换set1,将标准输入的字符串转为标准输出,如:
$tr a b
进入输入模式后,你所输入的所有的字母a都会被翻译成字母b,然后输出到屏幕上
$ tr a b
apple
bpple
aabbcc
bbbbcc
在上面的脚本中,tr ' ' '_',将echo通过管道传入的字符串中所有的空格翻译为下划线,然后赋值给na变量,再使用mv命令,也就完成了替换。
tr命令的其他用法,set1, set2可以使用一些特殊字符来匹配,如:
$ tr [:lower:] [:upper:] //将所有的小写字母翻译为大写
hello
HELLO
what
WHAT
其他特殊字符:
[:alnum:]
all letters and digits
[:alpha:]
all letters
[:blank:]
all horizontal whitespace
[:cntrl:]
all control characters
[:digit:]
all digits
[:graph:]
all printable characters, not including space
[:lower:]
all lower case letters
[:print:]
all printable characters, including space
[:punct:]
all punctuation characters
[:space:]
all horizontal or vertical whitespace
[:upper:]
all upper case letters
[:xdigit:]
all hexadecimal digits
[=CHAR=]
all characters which are equivalent to CHAR
阅读(1066) | 评论(0) | 转发(0) |