If you need to find a string in a file, you would typically use:
grep -H "string to find" filename.ext
However, grep doesn’t handle a large number of files well. If you specify grep "string" * or even grep "string" `find ./`you may find yourself facing this error:
bash: /bin/grep: Argument list too long
If you need to search for a string in a lot of files then you can use a simple bash script to do the searching for you.

In this sample, I am looking for a string “sample string” in a directory named “./sample/”:
for i in `find ./sample/`; do grep -H "sample string" $i; done
This uses the find command to do the searching. It actually returns a list of filenames, which we can then grep one-by-one. The -H option tells grep to let us know the filename it found the string in so we can go right into that file to find the location of it.

You May Also Like

Replacing the Cable Box – Idea Dump

So it’s 4AM, but I woke up with some ideas about replacing…

Report a Phishing site to Google, Get a Witty Response

Visit http://www.google.com/safebrowsing/report_phish/ and report a phishing page this is the response: Report…

Default Grub Boot Commands for Ubuntu 7.10

I recently formatted my laptop and installed Windows first, using half of…

One Liner to Get External IP Address

Was poking around ServerFault this morning and came across a great one-liner…