InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Grep tutorials

  • Recursive grep exclude dir
  • Recursive grep with specific file pattern
  • grep without regex (fixed string)
 
  • Home
  • > Tutorials
  • > grep

How to do recursive grep with specific file pattern

By admin on Nov 16, 2015

Recursive grep is pretty handy way to searching a pattern in a directory recursively. Sometimes it is useful to restrict search to specific file pattern (e.g. *.php). One can use the following command for this:

$ grep -r --include="*.php" pattern /path/to/dir

Note that –include=”GLOB” skip files whose base name matches GLOB (using wildcard matching). A file-name glob can use *, ?, and […] as wildcards, and \ to quote a wildcard or backslash character literally.

In case you want to include multiple pattern, you can repeat –include as shown below:

$ grep -r --include="*.php" --include="*.html" pattern /path/to/dir

In case you want to exclude specific file patterns (e.g images, etc.) you can use –exclude as shown below:

$ grep -r --exclude="*.gif" --exclude="*.png" pattern /path/to/dir

Suggested posts:

  1. CSS visibility – hide an element keeping its space
  2. Git – show log of one user’s commits
  3. Mac – hide and unhide a file or directory
  4. How to clear default app on android
  5. Jenkins how to clone a project
  6. How to setup MailChimp Rss email campaign
  7. How to use google custom search for wordpress site
  8. How to view desktop site from android mobile
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Bash shell scripting, grep, Linux/Unix Command Line, Mac, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress