Say our folder structure looks like this:
/app
/app/data
...
/app/secondary
/app/secondary/data
I want to recursively search /app/data
but I do not want to search /app/secondary/data
.
From within the app folder, what would my grep command look like?
A directory can be excluded from the grep command search. The --exclude-dir option is used to specify the directory we want to exclude for the grep match.
By default, grep is case-sensitive. This means that the uppercase and lowercase characters are treated as distinct. To ignore the case when searching, invoke grep with the -i option. If the search string includes spaces, you need to enclose it in single or double quotation marks.
Method 1 : Using the option “-prune -o” We can exclude directories by using the help of “path“, “prune“, “o” and “print” switches with find command. The directory “bit” will be excluded from the find search!
If you trust a file, file type, folder, or a process that Windows Security has detected as malicious, you can stop Windows Security from alerting you or blocking the program by adding the file to the exclusions list. Caution: Only do this for files that you're confident are safe.
This will do the trick
grep -r --exclude-dir='secondary/data' PATTERN data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With