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???
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.
man grep
says
-R, -r, --recursive
Read all files under each directory, recursively; this is
equivalent to the -d recurse option.
And even more common is to use find with xargs, say
find <dir> -type f -name <shellglob> -print0 | xargs grep -0
where -print0
and -0,
respectively, would use null char to separate entries in order to avoid issues with filenames having space characters.
精彩评论