Finding patterns through out all subdir

Hi all experts,
here is a problem which i would appreciate ur expertise.

I need to do this:
Eg.
Find a number: 1234567 which i dunno which file and which folder
I do know which main folder it is in but it is hidden deep within a lot of subdir.

Is it possible to find the file? + output the lines that contain the results to a file ?

Using ksh. AIX version.

If u are curious why I need to do this, its for work purpose.

PLs help ! Thanks!
:frowning:

yes its possible and you actually have already hit on the solution! Use the find command! Example find . -exec grep "1234567" -print {} \; 2>/dev/null See man find for detailed information on using the find command.

OKIE thats cool. So how do you using the 'find' command to search for a list of

1234567
1223574
5243673
2356464

numbers ?

Use a grep option to search a list of occurences. See man grep for that. Or you could search one at a time (though it wouldnt be particularly fast if you searched a large directory tree). Remember that find is by nature, recursive. It will search from the directory that you specify down the tree and across file systems (unless you tell find otherwise). See the man pages for find and grep for greater detail. Also if you are searching many directories you will want to use xargs with find.

One performance refinement to google's method when the number of files is large is to do something like this:

find . -type f | xargs egrep '1234567|1223574|5243673|2356464'

There are three features to this:

[list=1]
[]Use "-type f" to not grep directories as files, etc.
[
]Pipe the result through xargs to get as many files per grep as your OS/shell allows
[*]Use egrep to search multiple patterns
[/list=1]
ISTR there are versions of grep that will read a pattern list from a file --- consult your man pages.