Searcg for text string in unix files

I have a task that I have no idea how to do.  I am supposed to search through dozens of directories on our Unix system and find every occurrence of a string in the files.  I need to list the location and name of the files as well.

Any help?
Who is Participating?
woolmilkporcConnect With a Mentor Commented:
What is your OS? HPUX?

If so you can try

find directory -type f -print |xargs grep "string" /dev/null

To display just names of files with matches:

find directory -type f -print |xargs grep -l "string"

basically it's

grep -R "string" directory

If you need only filenames, not matching lines it's

grep -lR "string" directory

Please note that the above commands search the subdirectories of "directory" as well, so if the directories you have to search in are all under the same top level directory you'll have to issue the command only once against that top level directory.
Barry62Author Commented:
-R is apparently an illegal option
Barry62Author Commented:
Yes, it is HPUX.  I will try again Monday morning
Barry62Author Commented:
That worked.  Thanks!  

I added an i to the l option because I needed a non-case sensitive script.  But that got me what I needed.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.