Help using grep to search for a text string

vikingshelmut

100% Bull Plop
I need some help.

I've tried the man file, but can't figure it out. How do I search my entire drive for any file containing a string of text? For example, if I wanted to search / for the string "this is a string" in any file, I want it to return to me the names of the files that contain "this is a string".

I'm having trouble with the syntax. Logic would tell me to try:
grep "this is a string" /
This doesn't work, however.

Can you help a brotha out?
 
You want to use a combination of grep and find. Try:
Code:
find / -type f -exec grep "your string here" {} \; -ls

That will grep every file under / for the string "your string here" and print out the files ls info.

Brian
 
In this case, the Finder would actually *likely* be faster at this task, since it builds a nightly index of file contents. Using File>Find... and specifying a file contents search would be the thing to do.

Then again, this is the Darwin forum...
 
If you find yourself needing to do these types of searches frequently (i.e. text strings within the contents of a file), you will probably appreciate SpeedSearch X, since that is its forte:
http://w3.gorge.net/brunk/speedsearch/

The find / grep method is painfully slow when you have multi-gigabytes of files to search through.
 
You really want to search your whole system for a certain string? Its not really recomended (try to narrow the search field if you can), but you can do it like this:
Code:
$ grep -r "your string here" /
The '-r' makes grep recurse down the directory tree.
 
Back
Top