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 05-17-2012, 02:41 PM   #1
kamaleshbv1
LQ Newbie
 
Registered: Apr 2011
Posts: 29

Rep: Reputation: 0
replace name globally within a directory


Hello,

I would like to replace a word in all of my sub-directries,files globally within in a directory . Would like to get a suggestion from you and really appreciate for your help.
 
Old 05-17-2012, 02:48 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,470

Rep: Reputation: Disabled
You have words in your directories? I only have files.

Do you want to rename files with certain names, or do you want to replace text inside files?
 
Old 05-18-2012, 12:08 AM   #3
kamaleshbv1
LQ Newbie
 
Registered: Apr 2011
Posts: 29

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Ser Olmy View Post
You have words in your directories? I only have files.

Do you want to rename files with certain names, or do you want to replace text inside files?
To be specific ...it's for my dream weaver directory. I have large number of directories and sub directries and files which consits of information related to web sites.So recently i changed name to one my directories for which i need to replace the name in the linked files.This i want to do globaally rather than going into individual file and changing them which is time consuming.
 
Old 05-18-2012, 12:13 AM   #4
saivnoba
Member
 
Registered: Aug 2010
Distribution: Debian Sid, openSUSE, Gentoo, Slackware64
Posts: 68

Rep: Reputation: 2
What linux distro and desktop environment are you using. I think XFCE desktop has some batch rename program. Search for something similar (I read somewhere pyRename or pyRenamer).
 
Old 05-18-2012, 12:28 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
So I would suggest sed used with find and perhaps fed into a loop depending on the complexity of the change. This may sound a little vague, but so far, so has your description.
You will need to provide examples if you want more than suggested solution path?
 
Old 05-18-2012, 04:54 AM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,470

Rep: Reputation: Disabled
Quote:
Originally Posted by kamaleshbv1 View Post
To be specific ...it's for my dream weaver directory. I have large number of directories and sub directries and files which consits of information related to web sites.So recently i changed name to one my directories for which i need to replace the name in the linked files.This i want to do globaally rather than going into individual file and changing them which is time consuming.
An algorithm like this in a script should do the trick:
function replace_text($name)

if $name is a directory, then
{
for every $directory_entry in $name, do:
{
call replace_text($directory_entry)
}
done
}
else
{
# You may want to add some logic here to
# exclude certain files
sed --in-place=.bak "s/old-text/new-text/g" $name
}
end if
Are you using the bash shell?

Last edited by Ser Olmy; 05-18-2012 at 04:59 AM.
 
  


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] safely mv directory to another partition and replace with symlink mmtrebuchet Linux - Newbie 5 06-04-2012 03:09 PM
Best way to merge two directory trees with replace? legacyprog Linux - General 5 12-24-2011 09:15 PM
What is the best way to find & replace in a directory and all sub-directories mostanser Linux - Newbie 4 04-06-2009 11:31 PM
I want to replace my Active directory windows2003, what linux os best suite? Bertolomo Linux - Server 9 05-18-2008 06:17 PM
sed attempting to replace text with directory path emgey Programming 5 04-03-2008 08:05 PM

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

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