grep: File and Directory Selection

 
 2.1.6 File and Directory Selection
 ----------------------------------
 
 ‘-a’
 ‘--text’
      Process a binary file as if it were text; this is equivalent to the
      ‘--binary-files=text’ option.
 
 ‘--binary-files=TYPE’
      If a file’s data or metadata indicate that the file contains binary
      data, assume that the file is of type TYPE.  Non-text bytes
      indicate binary data; these are either output bytes that are
      improperly encoded for the current locale (⇒Environment
      Variables), or null input bytes when the ‘-z’ (‘--null-data’)
      option is not given (⇒Other Options).
 
      By default, TYPE is ‘binary’, and ‘grep’ suppresses output after
      null input binary data is discovered, and suppresses output lines
      that contain improperly encoded data.  When some output is
      suppressed, ‘grep’ follows any output with a one-line message
      saying that a binary file matches.
 
      If TYPE is ‘without-match’, when ‘grep’ discovers null input binary
      data it assumes that the rest of the file does not match; this is
      equivalent to the ‘-I’ option.
 
      If TYPE is ‘text’, ‘grep’ processes binary data as if it were text;
      this is equivalent to the ‘-a’ option.
 
      When TYPE is ‘binary’, ‘grep’ may treat non-text bytes as line
      terminators even without the ‘-z’ (‘--null-data’) option.  This
      means choosing ‘binary’ versus ‘text’ can affect whether a pattern
      matches a file.  For example, when TYPE is ‘binary’ the pattern
      ‘q$’ might match ‘q’ immediately followed by a null byte, even
      though this is not matched when TYPE is ‘text’.  Conversely, when
      TYPE is ‘binary’ the pattern ‘.’ (period) might not match a null
      byte.
 
      _Warning:_ The ‘-a’ (‘--binary-files=text’) option might output
      binary garbage, which can have nasty side effects if the output is
      a terminal and if the terminal driver interprets some of it as
      commands.  On the other hand, when reading files whose text
      encodings are unknown, it can be helpful to use ‘-a’ or to set
      ‘LC_ALL='C'’ in the environment, in order to find more matches even
      if the matches are unsafe for direct display.
 
 ‘-D ACTION’
 ‘--devices=ACTION’
      If an input file is a device, FIFO, or socket, use ACTION to
      process it.  If ACTION is ‘read’, all devices are read just as if
      they were ordinary files.  If ACTION is ‘skip’, devices, FIFOs, and
      sockets are silently skipped.  By default, devices are read if they
      are on the command line or if the ‘-R’ (‘--dereference-recursive’)
      option is used, and are skipped if they are encountered recursively
      and the ‘-r’ (‘--recursive’) option is used.  This option has no
      effect on a file that is read via standard input.
 
 ‘-d ACTION’
 ‘--directories=ACTION’
      If an input file is a directory, use ACTION to process it.  By
      default, ACTION is ‘read’, which means that directories are read
      just as if they were ordinary files (some operating systems and
      file systems disallow this, and will cause ‘grep’ to print error
      messages for every directory or silently skip them).  If ACTION is
      ‘skip’, directories are silently skipped.  If ACTION is ‘recurse’,
      ‘grep’ reads all files under each directory, recursively, following
      command-line symbolic links and skipping other symlinks; this is
      equivalent to the ‘-r’ option.
 
 ‘--exclude=GLOB’
      Skip any command-line file with a name suffix that matches the
      pattern GLOB, using wildcard matching; a name suffix is either the
      whole name, or a trailing part that starts with a non-slash
      character immediately after a slash (‘/’) in the name.  When
      searching recursively, skip any subfile whose base name matches
      GLOB; the base name is the part after the last slash.  A pattern
      can use ‘*’, ‘?’, and ‘[’...‘]’  as wildcards, and ‘\’ to quote a
      wildcard or backslash character literally.
 
 ‘--exclude-from=FILE’
      Skip files whose name matches any of the patterns read from FILE
      (using wildcard matching as described under ‘--exclude’).
 
 ‘--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.
 
 ‘-I’
      Process a binary file as if it did not contain matching data; this
      is equivalent to the ‘--binary-files=without-match’ option.
 
 ‘--include=GLOB’
      Search only files whose name matches GLOB, using wildcard matching
      as described under ‘--exclude’.  If contradictory ‘--include’ and
      ‘--exclude’ options are given, the last matching one wins.  If no
      ‘--include’ or ‘--exclude’ options match, a file is included unless
      the first such option is ‘--include’.
 
 ‘-r’
 ‘--recursive’
      For each directory operand, read and process all files in that
      directory, recursively.  Follow symbolic links on the command line,
      but skip symlinks that are encountered recursively.  Note that if
      no file operand is given, grep searches the working directory.
      This is the same as the ‘--directories=recurse’ option.
 
 ‘-R’
 ‘--dereference-recursive’
      For each directory operand, read and process all files in that
      directory, recursively, following all symbolic links.