Is there an easy way to search inside 1000s of files in a complex directory structure to find files which contain a specific string within the file?
2 Answers
grep -H -R searchstring /directory
may want to redirect the results to a file (or tee)
You may also want to look at ack
- 
        Note that not all versions of grep support the -R option.gabe.– gabe.2011-06-14 17:49:47 +00:00Commented Jun 14, 2011 at 17:49
- 
        if grep does not support -R you can allways do: cat /directory/* | grep -H searchstringWolfy– Wolfy2011-06-15 06:37:57 +00:00Commented Jun 15, 2011 at 6:37
- 
        @Wolfy, this is not the same, especially if you have a complex directory structure ... And-Hdoes not help you here.maxschlepzig– maxschlepzig2011-06-15 19:31:10 +00:00Commented Jun 15, 2011 at 19:31
- 
        
- 
        1You can use find and xargs.find -print0 -type f | xargs -0 grep -H searchstringuser26112– user261122013-04-20 11:58:46 +00:00Commented Apr 20, 2013 at 11:58
Yes, there is grep. It has an option for recursive directory traversal, e.g.:
$ grep -r specificstring path
With GNU grep you can restrict the searched files with the --include and --exclude pattern options.
-H ('Print the file name for each match') is the default with -r, -R and when you specify multiple files on the command line. -R also turns on recursive directory traversal but also follows symbolic links.
You can also pipe the results of grep to less for screen paging.