Recursive grep and filename wildcards

You can call grep with the -r switch to make it search recursively.

To search all files under /dir for "blah", run the following:

grep -r blah /dir

You can not use wildards directly in this manner, for example, the following will not search all text files:

grep -r blah *.txt

This doesn't work because the wildcard is expanded by the shell before grep is called. Instead, search the current directory (or whichever one you want) and pass the --include option:

grep -r blah . --include "*.txt"

References

Last modified: 03/06/2008 Tags: (none)

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top