LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-24-2003, 03:04 PM   #1
smc_one
LQ Newbie
 
Registered: Jul 2003
Posts: 11

Rep: Reputation: 0
How to rename directories in one line


Ive read some posts here on how to modify multiple files in a directory using a for/while loop with grep..

How would one go about doing a search/replace for a portion of a directory name..

ie..

"Change all instances of images to new_images in directory "x" and all subdirectories"

/home/directory/images/thumbnails

to

/home/directory/new_images/thumbnails..

Is this possible without writing a script?
 
Old 09-24-2003, 03:31 PM   #2
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
Why don't you just do
mv /home/directory/images /home/directory/new_images
 
Old 09-24-2003, 03:49 PM   #3
smc_one
LQ Newbie
 
Registered: Jul 2003
Posts: 11

Original Poster
Rep: Reputation: 0
The problem is I have to "find" these directories in a nest of several hundred directories.. So it would take hours to manually go through the directories recursively and find/rename them.. I was hoping a script command could do it for me
 
Old 09-24-2003, 04:48 PM   #4
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
Stupid script to try...
WARNING if you have images/images then you may run into trouble. or /home/foo/imagesthatIdontwanttochange/images may be changed to something you don't want because it contains images...

echo "this will generate a script to rename images to new_images"
find . -name images > /tmp/junk123
find . -name images | sed 's/images/new_images/' > /tmp/junk124
paste /tmp/junk123 /tmp/junk124 | sed 's/^/mv /'
rm /tmp/junk123 /tmp/junk124

This script will just spit out the output to the screen. If you want to redirect it to another file then execute the file that's up to you. If you want to highlight the output and do it that way it's up to you... I would certainly test and retest to make sure it is doing what you want. before you do it on a production environment... hope that was enough of a disclaimer...

edit: I am also assuming you have a base directory you will start from and not just searching from /

Last edited by Blinker_Fluid; 09-24-2003 at 04:49 PM.
 
  


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
Script to rename directories superior88 Linux - Newbie 4 02-15-2005 11:31 PM
cant rename directories andy753421 Linux - General 1 08-16-2004 09:24 AM
Rename a bunch of directories cessburn Linux - Software 1 06-07-2004 09:52 PM
rename with command line shanenin Linux - Software 1 09-25-2003 08:03 PM
how to rename directories Chijtska Linux - General 1 03-04-2002 08:52 AM


All times are GMT -5. The time now is 01:12 AM.

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