【发布时间】:2017-01-17 15:02:38
【问题描述】:
我正在尝试为当前目录和所有子目录中所有不是.sh 文件的文件添加前缀,其中bash 使用find。
问题是我得到一个错误:
mv: cannot move './test.txt' to 'PRE_./test.txt': No such file or directory
我的单行是:
find -type f ! -name "*.sh" -exec sh -c 'mv "{}" PRE_"{}"' _ {} \;
我也试过 xargs 和 rename:
find -type f ! -name "*.sh" -print0 | xargs -0 rename 's/(.*)$/PRE_$1/'
但我遇到了同样的错误。 怎么了? 提前致谢!
【问题讨论】:
-
cannot move './test.txt' to 'PRE_./test.txt'似乎是一个非常明确的信息——看看你想给它取的新名字,这是你想要的吗?您正在为整个路径添加前缀,而不仅仅是文件名。 -
就在当前目录下,还是在当前目录下的所有子目录下?
-
哦,忘了说:我也想重命名所有子目录中的文件。