重命名多个目录匹配模式 [英] Rename multiple directories matching pattern

查看:74
本文介绍了重命名多个目录匹配模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重命名baseir下与名称匹配的所有目录.例如:

I would like to rename all directories under a basedir which match a name. For example:

basedir/中,我有:

- foo/bar/blah
- my/bar/foo
- some/bar/foo1
- other/foo/bar

我想重命名所有匹配bar的目录,但是我想保留前缀部分.

I would like to rename all directories matching bar, but I would like to preserve the prefix part.

使用find,我可以轻松地列出所有目录,如下所示:

With find, I can easily make a list of all the directories like this:

find . -name repositoryunit -type d

但是,如何使用-exec mv {} ...(或与其他应用程序结合使用)以保留前缀?

However, how can I use -exec mv {} ... (or perhaps combine with another app) so that the prefix is preserved?

非常感谢!

推荐答案

find . -depth -name bar -type d -execdir mv {} baz \;

-execdir在执行命令之前将目录更改为父目录,因此此处的mv对于每个父目录都是本地的.

-execdir changes directory to the parent before executing the command, so the mv here will be local to each parent directory.

这篇关于重命名多个目录匹配模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆