Case sensitive searching in Linux

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

alwbtc

Posted 2011-08-06T22:43:08.080

Reputation: 2 367

4Did you not understand the descriptions given in the man pages? – Ignacio Vazquez-Abrams – 2011-08-06T22:44:58.480

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 – 2011-08-07T00:01:17.433

2Because 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 – 2011-08-07T00:10:40.813

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 – 2011-11-21T12:25:41.093

Answers

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

user unknown

Posted 2011-08-06T22:43:08.080

Reputation: 1 623

2

GNU grep has a recursive option:

grep -Hn something -r .

Casper

Posted 2011-08-06T22:43:08.080

Reputation: 191