Name
grep
Synopsis
grep [options] pattern [files]Search one or more files for lines that match a regular expression pattern. Regular expressions are described in Chapter 9. Exit status is 0 if any lines match, 1 if none match, and 2 for errors. See also egrep and fgrep.
Options
- -a, --text
Don’t suppress output lines with binary data; treat as text.
- -b, --byte-offset
Print the byte offset within the input file before each line of output.
- -c, --count
Print only a count of matched lines. With -v or --revert-match option, count nonmatching lines.
- -d action, --directories= action
Define an action for processing directories. Possible actions are:
- read
Read directories like ordinary files (default).
- skip
Skip directories.
- recurse
Recursively read all files under each directory. Same as -r.
- -e pattern, --regexp= pattern
Search for pattern. Same as specifying a pattern as an argument, but useful in protecting patterns beginning with -.
- -f file, --file= file
Take a list of patterns from file, one per line.
- -h, --no-filename
Print matched lines but not filenames (inverse of -l).
- -i, --ignore-case
Ignore uppercase and lowercase distinctions.
- -l, --files-with-matches
List the names of files with matches but not individual matched lines; scanning per file stops on the first match.
- --mmap
Try to use memory mapping (mmap) to read input in order to save time.
- -n, --line-number
Print lines and their line numbers.
- -q, --quiet, --silent
Suppress normal output in favor of quiet mode; scanning stops on ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access