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