user6538837 user6538837 - 6 months ago 37
Linux Question

Grep excluding directory

I found this solution to searching while excluding one directory in the answer to another question:

grep -r --exclude-dir="/x/y/z" 'pattern' /x/y

However, my search results still include things found in /x/y/z.


It seems --exclude-dir matches just the directory name, not its path. So, you can try

grep -r --exclude-dir=z 'pattern' /x/y

It might skip /x/y/a/b/c/z also, though.