10

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?

4 Answers 4

18

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.

9
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).
4
  • it says "find: missing argument to 'grep'"
    – webnat0
    Feb 19, 2011 at 19:49
  • works here. how did you replace "test here" ? Feb 19, 2011 at 19:51
  • 1
    @Daeyun: There is only one backslash. Feb 19, 2011 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. Feb 19, 2011 at 22:35
1

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

1

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" {} \;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .