我有以下命令:
find demoLibrary* -type d -execdir bash -c 'mv "$1" "${1/demoLibrary/foo}"' - {} \;
将目录demoLibrary
和分别重命名demoLibraryTests
为foo
和fooTests
;但也会写入以下输出:
find: ‘./demoLibrary’: No such file or directory
find: ‘./demoLibraryTests’: No such file or directory
是什么导致了这种输出?有什么建议可以解决此问题吗?
答案1
在您的示例中,每次匹配都会执行一个子 shell,这会占用大量资源。更好的方法是将结果通过管道传输到 rename。
$ find -depth -type d \
-name 'foo*' -print0 | rename -0 -d 's!^foo!bar!'
Reading filenames from file handle (GLOB(0x5594a9a71a48))
./fooone/footwo/foothree renamed as ./fooone/footwo/barthree
./fooone/footwo renamed as ./fooone/bartwo
./fooone renamed as ./barone