Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I want to search all files recursively from the directory I am in for a particular string.

I tried grep -r -i my_string

and I tried it in a test folder with two tiny files but it wouldnt find the string

could someone please help? also, is there any special way of defining "contains" rather than matching the whole word?

share|improve this question
Try grep -r -o -i "your_string" *(with " quotes). – pl1nk Jun 2 '12 at 1:31
i am getting a few permission denied messsages, does it just ignore those files but continue checking the rest? – David Jun 2 '12 at 2:40
Right, these files are getting ignored. – pl1nk Jun 2 '12 at 12:15

Are you searching for a file name or a word inside a file? grep searches inside the files, which seems to be what you want.

grep uses regular expressions - in fact, that's what the "re" part stands for. So, it does not use the normal bash wildcards; that is, abc* would not find words starting with abc, it would find words starting with ab, then zero or more c's following. But yes, if you simply give it a pattern, it will find it anywhere, with no knowledge of whole words. If you wanted to find whole words, you would need to create a regular expression to tell it that.

But, like most commands, you need to put the filename(s) at the end of the command, so your example would just sit there and wait for the filename.

As @plink said, use grep -r -o -i "your_string" * (or ., or other filespec). The errors can be ignored. If you are getting a lot of errors, you can append 2>/dev/null to the end, which will redirect stderr to a null device.

share|improve this answer

Your Answer


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.