user6538837 user6538837 - 1 year ago 154
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download