Linux operating system (13): grep command

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_41554005/article/details/100560717

Linux grep command

Overview:

Linux grep command is used to find files that match the criteria string.
grep command is used to find content that contains the specified template style file if the contents of a file found to comply with the specified style templates, preset grep command that will contain a column style template is displayed. Without specifying any file name or file name is given - , the grep command will read the data from the standard input.

The family includes Unix grep grep, egrep and fgrep. egrep and fgrep grep command with only a very small difference. grep egrep is extended to support more re metacharacters, fgrep is fixed grep or fast grep, they put all the letters as words, that is, regular expression meta-character representation back to the literal meaning of its own It is no longer special. linux using the GNU version of grep. It is more powerful and can be used by egrep and fgrep functionality -G, -E, -F command line option.

grammar

grep [-abcEFGhHilLnqrsvVwxy][-A<显示列数>][-B<显示列数>][-C<显示列数>][-d<进行动作>][-e<范本样式>][-f<范本文件>][--help][范本样式][文件或目录...]

parameter:

-a --text # Do not ignore binary data.
-A <the number of lines> --after-context = <number of lines displayed> # Match Template addition to displaying the row outside the pattern, and then display the contents of the row.
-b --byte-offset # Prior to demonstrate compliance with the line style, mark the first character of the line number.
-B <the number of lines> --before-context = <number of lines displayed> # compliance in addition to displaying the line pattern outside, and displays the contents of the previous row.
-c --count # calculated in line with the number of columns style.
-C <the number of lines> --context = <number of lines displayed> or - <number of display lines> # In addition to displaying the line style than meet, and the display contents before the row.
-d <action> --directories = <action> # when specified to look for is a directory rather than a file, you must use this parameter, otherwise the grep command will return information and stop action.
-e <template style> --regexp = <template style> # Find the file contents as specified string style.
-E --extended-regexp # representation styles extending ordinary use.
-f <rule file> --file = <rule file> # Specify rules file, the contents of which contain one or more regular pattern, so grep to find content file rule conditions are met, the format for each line of a regular pattern.
-F --fixed-regexp # regarded as the style list of fixed strings.
-G --basic-regexp # will be treated as ordinary style notation to use.
-h --no-filename # Prior to demonstrate compliance with the line style, does not indicate the file name of the row belongs.
-H --with-filename # Prior to demonstrate compliance with the line style, represents a file name of the row belongs.
difference -i --ignore-case # ignore character case.
-l --file-with-matches # list the contents of the documents in line with the file name specified style.
-L --files-without-match # list the contents of the file file name does not comply with the specified style.
-n --line-number # Prior to demonstrate compliance with the line style, mark the number of columns in the row number.
-q --quiet or -silent # does not display any information.
-r --recursive # effect of this parameter and specify the same "-d recurse" parameter.
-s --no-messages # does not display an error message.
-v --revert-match # show lines that do not match the text.
-V --version # show version information.
-w --word-regexp # is displayed only in line with the whole-word column.
-x --line-regexp # is displayed only in line with the whole row of columns.
-y # effect of this parameter and the specified "-i" the same parameters.
^ # Sign at the beginning of all output to a specified pattern row
$ # symbol output all lines to the end of the specified pattern

Examples

Find keyword file
grep 'linux' test.txt
multiple files to find keywords
grep 'linux' test.txt test2.txt

Guess you like

Origin blog.csdn.net/qq_41554005/article/details/100560717