Rename multiple directories with one domain name to another domain name?

I have many directories with some phrase (domain name) in her name. You must change this phrase to another (different domain name). How to do it 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 ... 
+4
source share
2 answers
 $ 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 
+15
source

You can also use rename , which comes with perl.

 $ rename 's/somewhere/elsewhere/' * 
0
source

Source: https://habr.com/ru/post/1393942/


All Articles