How to search a file within the sub folders?

Hi All,

I'm looking for the UNIX shell script to search a file having some characters within a particular path which intern have many sub folders in it.

Regards
Anil

It's not clear what you are asking. Are you searching for a file name? Or do you want to find which file has some characters in its contents?

If you are searching for a file with certain characters in it's name, the find command is probably what you want.

If you are searching for a file with certain characters in it's contents, the grep command is probably what you want.

Hi KenJackson,
Thanks for the reply.

Let me explain the requirement in detail:

Lets say i'm currently in /apps/appl_top/adm

under this path there are many folders ex : SQL,BIN,REPORTS.Under each folders there are sub folders in which there are files.

Now I want to search a file xxxxx.x having word "yyyy" in the /adm path.

I can use grep to search a particular file in a single directory.But i'm looking for a script or command that can search a file xxxxx.x having word "yyyy" in all the dfolders under /adm path.

Regards
Anil

Then try this. The -H switch tells grep to print the filename. The funny syntax, '{}' \;, is just the way find works.

find /adm -type f -exec grep -H yyyy '{}' \;

If there aren't too many files for grep to handle on one command line, you can do it this way:

grep yyyy $(find /adm -type f)
find /apps/appl_top/adm/ -type f -name "xxxxx.x" -exec grep -iH "yyyy" {} \;

Save some time and energy by using that slightly modified syntax:

find /adm -type f -exec grep -H yyyy '{}' +

or

find /apps/appl_top/adm/ -type f -name "xxxxx.x" -exec grep -iH yyyy {} +

Hi All,

Thank you so much.
You guys are too good.

Regards
Anil

grep -rl "XXXXXX" /home/user/

will take some time