About the Linux grep command

grep command format:

grep [-acinv] [-color=auto] 'Search string' filename

Options and parameters:

-a: Search binary files for data as text files

-c: count the number of times the 'search string' was found

-i: ignore the difference in case, so the case is treated as the same 

-n: output line number

-v: reverse selection, i.e. show lines without 'search string' content

Advanced grep command:

grep [-A][-B] [--color=auto] 'Search string' filename

Options and parameters:

-A: A number can be added after, which means after. In addition to listing the new line, the subsequent n lines are also listed.

-B: Numbers can be added behind, which means before. In addition to listing this line, the previous n lines are also listed.

--color=auto: Color the extracted keywords

 

grep is a very common and commonly used command. Its most important function is to compare the string data, and then print out the string that meets the user's needs. When grep searches for a string in the data, it extracts the data in units of "whole lines".

In terms of keyword display, grep can use --color=auto to display the keyword part in color. But if you have to add --color=auto every time you use grep, it will be very troublesome. At this point, you can add this line to ~/.bashrc: alias grep='grep --color=auto', and then source ~/.bashrc to take effect immediately.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326255877&siteId=291194637