Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to search the entire server by content. (text file)

When I try grep -rl "text here", it freezes.

How would you do it?

And how long does it usually take?

share|improve this question

migrated from stackoverflow.com Feb 19 '11 at 21:10

This question came from our site for professional and enthusiast programmers.

4 Answers 4

up vote 11 down vote accepted

You need to specify a file when using the grep command. With the command you're using, you're searching in the standard input...

Try grep -r "test" directory.

share|improve this answer
find / -name "*.txt" -exec grep "text here" {} \; -print 2>/dev/null

Which can be explained in human speak as:

  1. find
  2. starting from /
  3. in all files named *.txt (quotes are to bypass shell interpretation)
  4. with the resulting hits, perform the following
  5. grep "test here"
  6. in the file {}
  7. end of exec (\;) escaped end of statement
  8. print the files that match
  9. redirect error messages in sink (since you might not be root, otherwise just sudo it).
share|improve this answer
    
it says "find: missing argument to 'grep'" –  webnat0 Feb 19 '11 at 19:49
    
works here. how did you replace "test here" ? –  Alain Pannetier Feb 19 '11 at 19:51
    
oh. I had the wrong backslash. Thanks. :) –  webnat0 Feb 19 '11 at 19:53
1  
@Daeyun: There is only one backslash. –  Dennis Williamson Feb 19 '11 at 22:17
1  
@Dennis. Depends on your mother tongue. In Japan and Korea,there are several character sets in which the backslash is also rendered as the Yen sign or the Wong sign (0x5c). Also, please have a look at u+20E5. In the past there have been several exploits in IIS in which you could explore the whole disk (where IIS had its root) of a PC just by mixing real slash and false (other equivalent unicode converted down in the ascii plan) slashes and at least one using reverse solidus overlay. –  Alain Pannetier Feb 19 '11 at 22:35

you forget to specify what sort of files you want to search,
make sure you log in as root

cd /
grep -rl "text here" *  > /tmp/match.txt

this going to take a very long time, and you can collect the results later by checking /tmp/match.txt

share|improve this answer

The following command searches all the files ending with .txt in the the current working directory and all subdirectories:

find . -type f -name '*.txt' -exec grep -Hn "text here" {} \;

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.