2

In Linux, I want to search for a word in all files in a directory (also in subfolders), and the search must be case sensitive. The search must give me all file names, directory names, and line numbers containing this word.

Will the following do the search as I want? Could you please explain the flags and arguments here?

find . -type f | xargs grep -in WORD
4
  • 4
    Did you not understand the descriptions given in the man pages? Aug 6, 2011 at 22:44
  • look, if i had understood them, i wouldn't ask it here, right? why don't you give an answer to my question instead of being a smart-mouth?
    – alwbtc
    Aug 7, 2011 at 0:01
  • 2
    Because I would just give the answers found in the man pages. Which is why you need to tell us which parts you don't understand. Aug 7, 2011 at 0:10
  • Who migrated the question? On Windows, there is a find too, but it has a different syntax and will not work that way. There is a find in the unxtools (or unxutils?), which is a pure win32 application, not something you need cygwin for, but since the windows-find is in the path, it will not work either by simply installing the unixtools. Why was this question migrated here? U&L would have been the better target. Nov 21, 2011 at 12:25

2 Answers 2

4
find . -type f -exec grep -Hn WORD {} ";" 
  • xargs is almost always a bad combination with find, because find has a lot of exec-options (-exec, -execdir, -ok, -okdir) to perform commands on files, without needing to mask whitespace or problematic characters like * and ?.
  • -i is insensitive
  • -n print the line number
  • -H prints the filename in grep
2

GNU grep has a recursive option:

grep -Hn something -r .

You must log in to answer this question.

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