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 04-01-2009, 12:43 AM   #1
mostanser
LQ Newbie
 
Registered: Mar 2009
Posts: 6

Rep: Reputation: 0
What is the best way to find & replace in a directory and all sub-directories


Hi folks
please let me know what is the best way to find & replace in a directory and all sub-directories?

can I use sed for this?
 
Old 04-01-2009, 01:56 AM   #2
maxy7710
Member
 
Registered: Jan 2008
Location: Mumbai, india
Distribution: REDHAT, FEDORA,SUSE, UBUNTU, ORACLE ENTERPRISE LINUX & SOLARIS 10
Posts: 130

Rep: Reputation: 17
U want to find & replace directories & all its sub folders then use

find / -name 'directory-name'

this command will look for u r directory from " / "
 
Old 04-02-2009, 01:01 AM   #3
mostanser
LQ Newbie
 
Registered: Mar 2009
Posts: 6

Original Poster
Rep: Reputation: 0
hi
thanks for your help, but I just dont want to search strings in a files of a directory set rather I wanted to replace string. That is, search and replace.

is there any recursive idea with this??
I run this command:
find *.* -name .svn -prune -o -exec sed -i 's/google.com/yahoo.com/g' {} \;

it worked, but this is not a recursive process, please help...
 
Old 04-02-2009, 05:26 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
From the man page for 'find'
Quote:
-prune If -depth is not given, true; if the file is a directory, do not
descend into it.
If -depth is given, false; no effect.
so in your case it won't descend. Also, using '*.*' as the start point in find is probably wrong.
You're supposed to give the dir to start from ie the top of the dir tree you want to search. Usually it'll be one of :

. - current dir
/ - all dirs in system (prob not what you want)
/some/dir/path - specific other dir, ie not current dir
 
Old 04-06-2009, 10:31 PM   #5
mostanser
LQ Newbie
 
Registered: Mar 2009
Posts: 6

Original Poster
Rep: Reputation: 0
yes, you might be right

Code:
find *.* -name .svn -prune -o -exec sed -i 's/google.com/yahoo.com/g' {} \;
but this line worked for me with *.* and . not worked but I did not tried wusing placing any directory name. May be you right, but suddenly mine one worked..

Many thanks for your reply.
 
  


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
Find & Replace Command Linux shokeer Linux - Newbie 23 01-30-2012 11:04 PM
Can I use GREP to find & replace text? jim.thornton Linux - Newbie 3 07-18-2008 06:36 PM
Simple find&replace across 100 files saphil Linux - Newbie 2 01-03-2008 12:21 PM
Find & Replace Carriage Return in ooo linuxian Linux - Software 1 04-09-2005 05:43 PM
Find & Replace Benr Linux - Newbie 5 05-03-2004 02:37 PM

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

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