reference Flags

--exclude

Accepted by
opengrep scan, opengrep ci
Value
PATTERN, repeatable
See also
--include, --force-exclude, --semgrepignore-filename, paths, --exclude-minified-files, --exclude-rule, --max-target-bytes, --subdir, --use-git-ignore

Skips the files and directories whose path matches PATTERN. PATTERN uses the gitignore syntax:

Patterns that contain * must be quoted, or the shell expands them. The flag can be repeated; a path that matches any of the patterns is skipped.

--exclude adds to the other filters on the files found under directory targets: .gitignore, .semgrepignore, and the default ignore list (see opengrep scan). --include then keeps only the files matching one of its patterns. A rule's own paths narrow the files further for that rule.

Files named on the command line are scanned even when they match. With --force-exclude, the patterns that match the file name, such as *.py or gen.py, apply to them too.

Examples

Skip a directory

rule.yaml
rules:  - id: find-eval    pattern: eval(...)    message: found eval    languages: [python]    severity: WARNING
app.py
eval(code)
generated/gen.py
eval(code)
Command and result
$ opengrep scan -q --config rule.yaml --exclude generated .
app.py

  warn  find-eval
  found eval

     1: eval(code)

Files named on the command line

rule.yaml
rules:  - id: find-eval    pattern: eval(...)    message: found eval    languages: [python]    severity: WARNING
generated/gen.py
eval(code)
Command and result
$ opengrep scan -q --config rule.yaml --exclude generated generated/gen.py
generated/gen.py

  warn  find-eval
  found eval

     1: eval(code)
$ opengrep scan -q --config rule.yaml --exclude 'gen.py' --force-exclude generated/gen.py

The second command prints nothing: --force-exclude applies the pattern to the file named on the command line, so nothing is scanned and there are no findings.