This works for me, in that it excludes the "foo" directory from the root directory of the search:
grep -rn --exclude-dir=foo 'custom'
However this doesn't work:
grep -rn --exclude-dir=foo/bar 'custom'
But the "foo/bar" directory is still searched. I also tried it with quotes:
grep -rn --exclude-dir='foo/bar' 'custom'
I'm using Ubuntu 20.
Update
Although not perfect, I used this workaround instead:
grep -rn 'custom'|grep -v 'foo/bar'
This will fail to find lines that contain both "foo/bar" and "custom".
man 1 grepsays "skip any subdirectory whose base name matches". The base name offooisfoo, so it works; but the base name offoo/barisbar. Can you excludebar? or must it befoo/bar? (because you don't want to exclude otherbars). – Kamil Maciorowski Nov 02 '20 at 11:24firejail --blacklistis a general way to exclude any path, even if the tool you want to use doesn't support excluding. – Kamil Maciorowski Nov 02 '20 at 11:36