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-01-2007, 08:28 PM   #1
hammertime1983
LQ Newbie
 
Registered: Mar 2007
Posts: 15

Rep: Reputation: Disabled
Search for a string within a directory


Hello,

I am wanting to search through a whole directly for a string. i.e. search each file in the directory for the string and then list which files contain the word...

Does anyone know a way of doing this?
 
Old 11-01-2007, 08:33 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Try:

Code:
grep word ./directory/*
 
Old 11-01-2007, 08:36 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
There are several ways, here are a few:
Code:
grep -r 'search-string' /path/to/dictory/*
find /path/to/dictory -exec grep 'search-string' {} \;
find /path/to/dictory | xargs grep 'search-string'
The -r switch for grep is to run a recursive search, leave it off if you don't want sub-directories searched. find searches recursively by default, but you can limit that as well.
 
  


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
C....Search a string for a string Scrag Programming 4 06-14-2004 04:15 PM
search for my string alaios Linux - General 6 05-08-2004 01:32 PM
How do you search for a string? kau2 Linux - General 2 01-05-2004 06:51 PM
string search in C h/w Programming 17 10-13-2003 06:26 PM
recursive search of a string in a directory ?! realos Linux - Software 4 11-27-2002 04:49 AM

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

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