Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
linux:grep_recursively_through_single_file_extension [2013/08/21 15:31]
Joel Dare
linux:grep_recursively_through_single_file_extension [2020/06/01 22:53] (current)
Line 1: Line 1:
 +====== Grep Recursively Through Single File Extension ======
  
 +You can use the following //grep// command to search through a directory, recursively,​ but only looking at a specific file pattern.
 +
 +  grep -r --include=<​pattern>​ <​string>​ <​directory>​
 +
 +Here is an example that searches recursively starting at /home/joel/ and including only php files.
 +
 +  grep -r --include="​*.php"​ "​public auction"​ ./
 +
 +Other options you might want to add to the command:
 +
 +| -i | Case insensitive match. |
 +| -c | Count of matches; suppressing normal output. ​ One line per file match. |
 +| -o | Show only the part of a matching line that matches. |
 +
 +Here's another example with the -r, -i and -o options all added.
 +
 +  grep -rio --include="​*.php"​ "​public auction"​ ./
comments powered by Disqus