views:

52

answers:

2

i have to search for a particular text in files and for that im using grep command but it searches only in current folder.What i want is that using a single grep command i can search a particular thing in the current folder as well as in all of its sub folders.How can i do that???

+1  A: 

man grep says

   -R, -r, --recursive
          Read all  files  under  each  directory,  recursively;  this  is
          equivalent to the -d recurse option.
aioobe
i was trying this only but its not searching in sub directories
developer
which system are you on?
aioobe
+1  A: 

POSIX grep does not support recursive searching - the GNU version of grep does.

find . -type f -exec grep 'pattern' {} \;

would be runnable on any POSIX compliant UNIX.

jim mcnamara
aha. That's good to know!
aioobe
`find . -type f -exec grep 'pattern' {} /dev/null \;` is a top tip I picked up on here for printing the name of the file(s) before the matching line with POSIX grep.
Johnsyweb