Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 用一个域名将多个目录重命名为另一个域名?_Linux_Bash_Shell - Fatal编程技术网

Linux 用一个域名将多个目录重命名为另一个域名?

Linux 用一个域名将多个目录重命名为另一个域名?,linux,bash,shell,Linux,Bash,Shell,我有许多目录的名称中有一些短语(域名)。需要将该短语更改为另一个(另一个域名)。如何简单地做到这一点?示例如下: 之前: $ 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

我有许多目录的名称中有一些短语(域名)。需要将该短语更改为另一个(另一个域名)。如何简单地做到这一点?示例如下:

之前:

$ 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
...
之后

如果输出看起来正常:

$ for i in *; do echo mv $i ${i/somewhere/elsewhere}; done |sh

您还可以使用perl附带的
重命名

$ rename 's/somewhere/elsewhere/' *

非常感谢你!很好!你应该引用你的变量展开式,以防他的dir在名称中有空格。我没有把管道拿到sh,删除echo不是很简单吗?@Sorin:不太简单,向上箭头+
| sh
+enter比删除
echo
更快。这使执行的命令与屏幕上显示的命令非常接近。@SiegeX:如果我这样做,您会第一个指出包含
的文件名存在的问题,不是吗?;-)重复
$ for i in *; do echo mv $i ${i/somewhere/elsewhere}; done |sh
$ rename 's/somewhere/elsewhere/' *