LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2014, 08:22 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 709

Rep: Reputation: Disabled
Rename multiple directories


I have a bunch of directories:
Code:
/var/www/main/dir1/view
/var/www/main/dir2/view
/var/www/main/dir3/view
...
/var/www/main/dir50/view
I would like to rename them as follows:
Code:
/var/www/main/dir1/templates
/var/www/main/dir2/templates
/var/www/main/dir3/templates
...
/var/www/main/dir50/templates
However, the directories in question are tracked using Git. As such, I will need to do something like the following:
Code:
git mv <old name> <new name>
How can I do this without manually typing each command?

Thanks
 
Old 09-22-2014, 08:28 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Code:
for i in {1..50}; do 
  git mv /var/www/main/dir$i/view /var/www/main/dir$i/templates
done

Last edited by keefaz; 09-22-2014 at 08:32 AM. Reason: forgot a ;
 
1 members found this post helpful.
Old 09-22-2014, 08:30 AM   #3
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 709

Original Poster
Rep: Reputation: Disabled
Thanks keefaz,

I was delinquent on providing the whole store. My directory is not /var/www/main/dir1/view, but is really /var/www/main/someName/view.
 
Old 09-22-2014, 08:34 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,439

Rep: Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770
probably:
for i in /var/www/main/*
 
Old 09-22-2014, 08:44 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Tell the whole story then
Code:
for name in /var/www/main/*/view; do
   git mv $name $(dirname $name)/templates
done
 
Old 09-22-2014, 08:47 AM   #6
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 709

Original Poster
Rep: Reputation: Disabled
Thank you pan64 and keefaz!

Code:
for i in /var/www/main/*; do
git mv $i/view $i/templates
done
 
Old 09-22-2014, 08:51 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
So there are only dirs/view in /var/www/main?
 
Old 09-22-2014, 08:56 AM   #8
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 709

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
So there are only dirs/view in /var/www/main?
Yes. My original directories look like the following, and I just wish to change "view" to "templates"
Code:
/var/www/main/thisDir/view
/var/www/main/thatDir/view
/var/www/main/anotherDir/view
...
/var/www/main/andAnotherDir/view
 
Old 09-23-2014, 01:06 AM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,439

Rep: Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770
glad to help you.
if you think your problem is solved please mark the thread solved. Also if you want to say thanks just press yes....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Batch rename directories? junglepunk Linux - Newbie 3 03-13-2014 05:34 AM
cant rename directories andy753421 Linux - General 1 08-16-2004 08:24 AM
Rename a bunch of directories cessburn Linux - Software 1 06-07-2004 08:52 PM
How to rename directories in one line smc_one Linux - Newbie 3 09-24-2003 03:48 PM
how to rename directories Chijtska Linux - General 1 03-04-2002 07:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration