grep: File and Directory Selection

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