Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

bash

shell

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
...
like image 268
marioosh Avatar asked Jan 31 '12 10:01

marioosh


1 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
like image 188
mvds Avatar answered Oct 13 '22 07:10

mvds