LinuxQuestions.org
Visit Jeremy's Blog.
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 11-12-2005, 06:07 AM   #1
ekdya
Member
 
Registered: Oct 2003
Posts: 280

Rep: Reputation: 30
command to search


Hello

I looked every where includeing the doc related to egrep, I am trying to search all the files in all the sub-directories of a given directory for a given string, could some one please help
I don't think the distro makes a different but it is debian testing 2.6.13 just in case.

thanks
 
Old 11-12-2005, 06:21 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Here's one way of doing this:

find . -type f -exec egrep <searchstring> {} \;

Find will come up with all files (-type f) and give these to egrep. Egrep will search the given file for the <searchstring> you gave.

Hope this helps.
 
Old 11-12-2005, 10:22 AM   #3
imitheos
Member
 
Registered: May 2005
Location: Greece
Posts: 415

Rep: Reputation: 86
Re: command to search

Quote:
Originally posted by ekdya
Hello

I looked every where includeing the doc related to egrep, I am trying to search all the files in all the sub-directories of a given directory for a given string, could some one please help
I don't think the distro makes a different but it is debian testing 2.6.13 just in case.

thanks
Code:
egrep -r "search_string" *
or with find like druuna mentioned
 
Old 11-12-2005, 10:46 AM   #4
prabuayyappan
Member
 
Registered: Sep 2005
Location: Coimbatore
Distribution: Prabuayyappan
Posts: 32

Rep: Reputation: 15
1)find . -exec grep -q "searchstring" '{}' \; -print

If you want to just find each file then pass it on for processing use the -q grep option.

2)find . -exec grep "www.athabasca" '{}' \; -print

All files that contain the string will have their path printed to standard output.
 
  


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
search using description to get command? Linuxuser_81 Linux - Newbie 1 10-07-2005 01:59 PM
Find command using 2 search conditions nifflerX Linux - General 8 07-15-2005 02:37 PM
pattern search through find command. abhi Linux - Newbie 2 04-11-2005 11:31 AM
case insensitive search command ColKurtz Linux - Newbie 4 01-20-2005 08:02 AM
search my harddisk - which command ??? merlin23 Linux - Newbie 5 12-14-2004 12:46 PM


All times are GMT -5. The time now is 04:04 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration