Running YARA from the command-line

In order to invoke YARA you’ll need two things: a file with the rules you want to use (either in source code or compiled form) and the target to be scanned. The target can be a file, a folder, or a process.


Rule files can be passed directly in source code form, or can be previously compiled with the yarac tool. You may prefer to use your rules in compiled form if you are going to invoke YARA multiple times with the same rules. This way you’ll save time, because for YARA is faster to load compiled rules than compiling the same rules over and over again.

The rules will be applied to the target specified as the last argument to YARA, if it’s a path to a directory all the files contained in it will be scanned. By default YARA does not attempt to scan directories recursively, but you can use the -r option for that.

Available options are:

-t <tag> --tag=<tag>

Print rules tagged as <tag> and ignore the rest.

-i <identifier> --identifier=<identifier>

Print rules named <identifier> and ignore the rest.


Print not satisfied rules only (negate).

-D --print-module-data

Print module data.

-g --print-tags

Print tags.

-m --print-meta

Print metadata.

-s --print-strings

Print matching strings.

-e --print-namespace

Print rules’ namespace.

-p <number> --threads=<number>

Use the specified <number> of threads to scan a directory.

-l <number> --max-rules=<number>

Abort scanning after matching a number of rules.

-a <seconds> --timeout=<seconds>

Abort scanning after a number of seconds has elapsed.

-k <slots> --stack-size=<slots>

Allocate a stack size of “slots” number of slots. Default: 16384. This will allow you to use larger rules, albeit with more memory overhead.

New in version 3.5.0.

-d <identifier>=<value>

Define external variable.

-x <module>=<file>

Pass file’s content as extra data to module.

-r --recursive

Recursively search for directories.

-f --fast-scan

Fast matching mode.

-w --no-warnings

Disable warnings.

-v --version

Show version information.

-h --help

Show help.

Here you have some examples:

  • Apply rules on /foo/bar/rules1 and /foo/bar/rules2 to all files on current directory. Subdirectories are not scanned:

    yara /foo/bar/rules1 /foo/bar/rules2 .
  • Apply rules on /foo/bar/rules to bazfile. Only reports rules tagged as Packer or Compiler:

    yara -t Packer -t Compiler /foo/bar/rules bazfile
  • Scan all files in the /foo directory and its subdirectories:

    yara -r /foo
  • Defines three external variables mybool, myint and mystring:

    yara -d mybool=true -d myint=5 -d mystring="my string" /foo/bar/rules bazfile
  • Apply rules on /foo/bar/rules to bazfile while passing the content of cuckoo_json_report to the cuckoo module:

    yara -x cuckoo=cuckoo_json_report /foo/bar/rules bazfile