LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 01: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, 01:48 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

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-17-2012, 11:08 PM   #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-17-2012, 11:13 PM   #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-17-2012, 11:28 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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, 03:54 AM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,339

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 03:59 AM.
 
  


Reply



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

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

All times are GMT -5. The time now is 05:36 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
Open Source Consulting | Domain Registration