-E, –extended-regexp Interpret PATTERNS as extended regular expressions.
-F, –fixed-strings Interpret PATTERNS as fixed strings, not regular expressions.
-G, –basic-regexp Interpret PATTERNS as basic regular expressions. This is the default.
-P, –perl-regexp Interpret PATTERNS as Perl-compatible regular expressions (PCREs). This option is experimental when combined with the -z (–null-data) option, and grep -P may warn of unimplemented features.
-e PATTERNS, –regexp=PATTERNS Use PATTERNS as the patterns. If this option is used multiple times or is combined with the -f (–file) option, search for all patterns given. This option can be used to protect a pattern beginning with “-”.
-f FILE, –file=FILE Obtain patterns from FILE, one per line. If this option is used multiple times or is combined with the -e (–regexp) option, search for all patterns given. The empty file contains zero patterns, and therefore matches nothing.
-i, –ignore-case Ignore case distinctions, so that characters that differ only in case match each other.
-v, –invert-match Invert the sense of matching, to select non-matching lines.
-w, –word-regexp Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore. This option has no effect if -x is also specified.
-x, –line-regexp Select only those matches that exactly match the whole line. For a regular expression pattern, this is like parenthesizing the pattern and then surrounding it with ^ and $.
-y Obsolete synonym for -i.
General Output Control
-c, –count Suppress normal output; instead print a count of matching lines for each input file. With the -v, –invert-match option, count non-matching lines.
–color[=WHEN], –colour[=WHEN] Surround the matched (non-empty) strings, matching lines, context lines, file names, line numbers, byte offsets, and separators (for fields and groups of context lines) with escape sequences to display them in color on the terminal.
-L, –files-without-match Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.
-l, –files-with-matches Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.
-m NUM, –max-count=NUM Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search. When grep stops after NUM matching lines, it outputs any trailing context lines. When the -c or –count option is also used, grep does not output a count greater than NUM. When the -v or –invert-match option is also used, grep stops after outputting NUM non-matching lines.
-o, –only-matching Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
-q, –quiet, –silent Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected.
-s, –no-messages Suppress error messages about nonexistent or unreadable files.
Context Line Control
-A NUM, –after-context=NUM Print NUM lines of trailing context after matching lines.
-B NUM, –before-context=NUM Print NUM lines of leading context before matching lines.
-C NUM, -NUM, –context=NUM Print NUM lines of output context.
File and Directory Selection
-a, –text Process a binary file as if it were text; this is equivalent to the –binary-files=text option.
-D ACTION, –devices=ACTION If an input file is a device, FIFO or socket, use ACTION to process it.
-d ACTION, –directories=ACTION If an input file is a directory, use ACTION to process it.
–exclude=GLOB Skip any command-line file with a name suffix that matches the pattern GLOB, using wildcard matching;
–exclude-from=FILE Skip files whose base name matches any of the file-name globs read from FILE.
–exclude-dir=GLOB Skip any command-line directory with a name suffix that matches the pattern GLOB.
–include=GLOB Search only files whose base name matches GLOB.
-r, –recursive Read all files under each directory, recursively, following symbolic links only if they are on the command line. Note that if no file operand is given, grep searches the working directory. This is equivalent to the -d recurse option.
-R, –dereference-recursive Read all files under each directory, recursively.
find a file named test
ylspiritdeMacBook-Pro:grep ylspirit$ ls | grep "test"
find a file whose name is not test
ylspiritdeMacBook-Pro:grep ylspirit$ ls | grep -v "test"
ylspiritdeMacBook-Pro:grep ylspirit$ grep -a "13" *