LinuxSir.cn,穿越时空的Linuxsir!

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

这句话哪里错了,就是不过

[复制链接]
发表于 2008-6-12 15:01:01 | 显示全部楼层 |阅读模式
find -name "*[A-Z]*" -exec mv {} $(echo {} | tr A-Z a-z) \;
得到结果:
mv: `./XXX' and `./XXX' are the same file
mv: `./YYY' and `./YYY' are the same file
mv: `./ZZZ' and `./ZZZ' are the same file
……
为什么tr没有起作用呢?
试过把echo换ls,提示ls {}无该文件
发表于 2008-6-12 16:58:57 | 显示全部楼层
试下这个:

for f in $(find -name '*[A-Z]')
do
mv $f $(echo $f | tr A-Z a-z)
done
回复 支持 反对

使用道具 举报

发表于 2008-6-12 17:35:06 | 显示全部楼层
我觉得都是管道惹的祸,因为find不是shell,没有管道这样牛的功能。这就能解释为什么总是报“same file”消息,因为find不能识别管道符,相当于只执行了“find -name "*[A-Z]*" -exec mv {} $(echo {}) \;”。

相反,如果调用shell帮执行就能完成:
  1. find -name "*[A-Z]*" -exec bash -c 'mv {} $(echo {} | tr [A-Z] [a-z])' \;
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-6-13 09:54:35 | 显示全部楼层
果如楼上所说,多谢了
二楼这样好像也可以,也感谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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