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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-17-2012, 02:41 PM
|
#1
|
LQ Newbie
Registered: Apr 2011
Posts: 29
Rep:
|
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.
|
|
|
05-17-2012, 02:48 PM
|
#2
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep:
|
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?
|
|
|
05-18-2012, 12:08 AM
|
#3
|
LQ Newbie
Registered: Apr 2011
Posts: 29
Original Poster
Rep:
|
Quote:
Originally Posted by Ser Olmy
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.
|
|
|
05-18-2012, 12:13 AM
|
#4
|
Member
Registered: Aug 2010
Distribution: Debian Sid, openSUSE, Gentoo, Slackware64
Posts: 68
Rep:
|
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).
|
|
|
05-18-2012, 12:28 AM
|
#5
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,028
|
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?
|
|
|
05-18-2012, 04:54 AM
|
#6
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep:
|
Quote:
Originally Posted by kamaleshbv1
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.
|
|
|
All times are GMT -5. The time now is 09:25 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|