Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question

migrated from Nov 20 '11 at 18:05

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

Did you not understand the descriptions given in the man pages? – Ignacio Vazquez-Abrams Aug 6 '11 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 '11 at 0:01
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. – Ignacio Vazquez-Abrams Aug 7 '11 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. – user unknown Nov 21 '11 at 12:25
up vote 1 down vote accepted
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
share|improve this answer

GNU grep has a recursive option:

grep -Hn something -r .
share|improve this answer

You must log in to answer this question.

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