Why the accepted answer is incorrect
@Seamus's accepted answer is incorrect because it grep -r --exclude-dir=<glob>matches base names that, by definition, cannot contain slashes (slashes make it no-op efficiently, since no base name will match).
From the GNU Grep Guide :
- exclude-dir = glob
... , glob...
, ,
, OP , , ...
.
βββ app
βββ data
βββ secondary
βββ data
... app :
> grep -r <search-pattern> data
secondary data.
data, data, .
.
βββ data
βββ file.txt
βββ folder1
β βββ folder2
β βββ data
β β βββ file.txt
β βββ file.txt
βββ folder3
βββ data
β βββ file.txt
βββ file.txt
> grep -r --exclude-dir='data' <search-pattern> data/*
* . , data .