bash 将一个域名的多个目录重命名为另一个域名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9078181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:27:21 来源:igfitidea点击:
Rename multiple directories with one domain name to another domain name?
提问by marioosh
I have many directories with some phrase (domain name) in its name. Need to change that phrase to another one (another domain name). How to do that simply ? Example below:
我有很多目录,名称中带有一些短语(域名)。需要将该短语更改为另一个(另一个域名)。如何简单地做到这一点?下面的例子:
Before:
前:
$ ls /var/www
drwxr-x--- 12 apache apache 4096 Dec 16 10:28 somewhere.com
drwxr-xr-x 3 apache apache 4096 Jan 28 2011 maven.somewhere.com
drwxr-x--- 6 apache apache 4096 Feb 24 2010 mini.somewhere.com
drwxr-x--- 3 apache apache 4096 Jul 16 2010 ml.somewhere.com
...
After
后
$ ls /var/www
drwxr-x--- 12 apache apache 4096 Dec 16 10:28 elsewhere.com
drwxr-xr-x 3 apache apache 4096 Jan 28 2011 maven.elsewhere.com
drwxr-x--- 6 apache apache 4096 Feb 24 2010 mini.elsewhere.com
drwxr-x--- 3 apache apache 4096 Jul 16 2010 ml.elsewhere.com
...
回答by mvds
$ cd /var/www
$ for i in *; do echo mv $i ${i/somewhere/elsewhere}; done
if the output looks ok:
如果输出看起来没问题:
$ for i in *; do echo mv $i ${i/somewhere/elsewhere}; done |sh
回答by fajran
You can also use renamethat comes with perl.
你也可以使用renameperl 自带的。
$ rename 's/somewhere/elsewhere/' *

