Reputation: 32677
I would like to rename all directories under a basedir which match a name. For example:
In basedir/
, I have:
- foo/bar/blah
- my/bar/foo
- some/bar/foo1
- other/foo/bar
I would like to rename all directories matching bar
, but I would like to preserve the prefix part.
With find
, I can easily make a list of all the directories like this:
find . -name repositoryunit -type d
However, how can I use -exec mv {} ...
(or perhaps combine with another app) so that the prefix is preserved?
Many thanks in advance!
Upvotes: 15
Views: 9076
Reputation: 361984
find . -depth -name bar -type d -execdir mv {} baz \;
-execdir
changes directory to the parent before executing the command, so the mv
here will be local to each parent directory.
Upvotes: 27