LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-02-2008, 01:15 PM   #1
craftereric
LQ Newbie
 
Registered: Mar 2008
Posts: 21

Rep: Reputation: 15
need to move several directories


I have the current directory structure in /tmp:
utilityserver/REPLACE_COMPUTER_NAME/properties/
guiserver/REPLACE_COMPUTER_NAME/properties/
newserver/REPLACE_COMPUTER_NAME/properties/

(and so on - more directories with the same structure)

From /tmp, I would to rename the above directories as follows:
utilityserver/server1/properties/
guiserver/server1/properties/
newserver/server1/properties/

(and so on)

Is there a find -exec option that will do this? If not, what is the easiest way to do this?
 
Old 06-02-2008, 03:43 PM   #2
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
There might be a better way to do it, but you can run multiple commands from -exec if you run 'sh -c "...Your commands here...'.
So for example, you could have something like this (untested):
Code:
find . [how to identify directories] -exec sh -C 'olddir={};\
    curhost=$( hostname )
    new=$( echo $olddir | sed "s/REPLACE_COMPUTER_NAME/$curhost/" ); \
    mv $olddir $new ' \;
It should give you the idea anyway.
 
Old 06-02-2008, 04:29 PM   #3
craftereric
LQ Newbie
 
Registered: Mar 2008
Posts: 21

Original Poster
Rep: Reputation: 15
this worked - small revision

This worked beautifully with one small correction. Make the -C should be -c (lowercase). Thanks for the help.

Code:
find . [how to identify directories] -exec sh -c 'olddir={};\
    curhost=$( hostname )
    new=$( echo $olddir | sed "s/REPLACE_COMPUTER_NAME/$curhost/" ); \
    mv $olddir $new ' \;
Quote:
Originally Posted by beadyallen View Post
There might be a better way to do it, but you can run multiple commands from -exec if you run 'sh -c "...Your commands here...'.
So for example, you could have something like this (untested):
Code:
find . [how to identify directories] -exec sh -C 'olddir={};\
    curhost=$( hostname )
    new=$( echo $olddir | sed "s/REPLACE_COMPUTER_NAME/$curhost/" ); \
    mv $olddir $new ' \;
It should give you the idea anyway.
 
Old 06-02-2008, 05:57 PM   #4
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
Quote:
one small correction. Make the -C should be -c (lowercase).
Hence the 'untested' bit Glad it worked.
 
  


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
Howto move entire directories ? coolcargo Linux - Newbie 18 03-04-2007 12:30 AM
Very simple shell script - move files to different directories beley Programming 7 11-02-2006 06:24 AM
Move certain files into different directories facets Programming 6 05-28-2004 02:20 PM
partitioning a new drive, which directories can I move ? xucaen Linux - General 2 02-25-2004 10:03 PM
Can I move Untarred directories? Nigel_Tufnel Linux - General 5 08-08-2002 09:45 AM


All times are GMT -5. The time now is 11:42 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