The documentatiton for --exclude-dir
in the GNU grep
manual says
--exclude-dir=GLOB
Skip any command-line directory with a name suffix that matches
the pattern GLOB
. When searching recursively, skip any
subdirectory whose base name matches GLOB
. Ignore any redundant
trailing slashes in GLOB
.
As you can see, the given pattern (GLOB
) will be applied only to the actual filename of the directory, and since a directory name can't contain /
in its name, a pattern like /proc
will never match.
Therefore, you would have to use --exclude-dir=proc
and --exclude-dir=sys
(or --exclude-dir={proc,sys}
if you are short on time), and at the same time be aware that this would skip not only /proc
and /sys
but also any other directory with either of those names.
Another way of recursively searching a complete directory tree from the root down while avoiding these two directories is by using grep
from find
:
find / \( -type d \( -path /proc -o -path /sys \) -prune \) -o \
-type f -exec grep 'PATTERN' {} +
This would detect the two specific directories /proc
and /sys
and stop find
from descending into them. It would also feed any found regular file to grep
in as large batches as possible at a time.
--exclude-dir
is matching directory names (eg.sys
), not paths (eg./sys
)? – Jan 11 '19 at 23:42