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

Recursive grep and excluding directory

on Mar 19, 2016

Recursive grep is pretty handy way to searching a pattern in a directory recursively. Sometimes it is useful to exclude a specific directory (or multiple directories). One can use the following commands for this.

Exclude one directory

This will search recursively in all files in directory /path/to/dir except directory css. Note that directory name (not path) has to be specified.

$ grep -r --exclude-dir=css pattern /path/to/dir

Exclude multiple directories

This will search recursively in all files in directory /path/to/dir except directories css and js.

$ grep -r --exclude-dir=css --exclude-dir=js pattern /path/to/dir

Suggested posts:

  1. display method names from php WP_Query object
  2. Mac – hide and unhide a file or directory
  3. Iterate over specific file extension in a dir in shell script
  4. How to list git branches
  5. PHP execute command and capture shell exit status
  6. PHP – convert array to associative array
  7. Python map examples
  8. Git – show log of one user’s commits
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