Linux Usage of grep 1. The grep command in linux is a powerful text search tool. It can search text using regular expressions and print matching rows. Grep stands for Global Regular Expression Print, which indicates the Global Regular Expression version. Its permission is granted to all users. 2. Format: grep [options] 3. Main Parameter: [options] Main Parameter:-c: only counts matching rows are output. -I: case-insensitive (only applicable to single characters ). -H: When querying multiple files, the file name is not displayed. -L: When querying multiple files, only names containing matching characters are output. -N: displays matching rows and row numbers. -S: the error message that does not exist or does not match the text is not displayed. -V: displays all rows that do not contain matched text. The main parameter of the regular expression pattern is \: Ignore the original meaning of special characters in the regular expression. ^: Match the start line of the regular expression. $: Matches the end row of the regular expression. \ <: Starts from the row that matches the regular expression. \>: Ends with the row that matches the regular expression. []: A single character. For example, [A] indicates that A meets the requirements. [-]: Range, such as [A-Z], that is, A, B, C Until Z all meet the requirements ..: All single characters. *: It can contain 0 characters. 4. The grep command uses a simple instance $ grep 'test' d * to display all lines containing test in files starting with d. $ Grep 'test' aa bb cc is displayed in the aa, bb, and cc files that match the test row. $ Grep '[a-z] \ {5 \}' aa displays all rows of a string containing at least five consecutive lowercase characters. $ Grep 'W \ (es \) t. * \ 1' aa if the west is matched, the es is stored in the memory, marked as 1, and any characters (. *). These characters are followed by another es (\ 1). If they are found, the row is displayed. If you use egrep or grep-E, you do not need to escape it by using the "\" character. You can directly write it as 'W (es) t. * \ 1. 5. the grep command uses a complex instance. Assume that you are searching for a file with the string 'Magic 'in the'/usr/src/linux/doc' directory: $ grep magic/usr/src/linux/Doc/* sysrq.txt: * How do I enable the magic SysRQ key? Sysrq.txt: * How do I use the magic SysRQ key? The 'sysrp.txt 'file contains this string. The SysRQ function is discussed. By default, 'grep' only searches for the current directory. If there are many subdirectories in this directory, 'grep' will be listed in the following form: grep: sound: Is a directory, which may make 'grep' output hard to read. There are two solutions: Search for subdirectories: grep-r or ignore subdirectories: grep-d skip if there are many outputs, you can use the pipeline to transfer it to 'less '. Read: $ grep magic/usr/src/linux/Documentation/* | less, so that you can read it more conveniently. Note that you must provide a file filtering method (* for searching all files *). If you forget, 'grep' will wait until the program is interrupted. If this happens, press <CTRL c> and try again. The following are some interesting command line parameters: grep-I pattern files: case-insensitive search. By default, it is case sensitive. grep-l pattern files: only names of matched files are listed. grep-L pattern files: names of unmatched files are listed. grep-w pattern files: only the entire word is matched, instead of a part of the string (such as matching 'Magic ', rather than 'magical'), grep-C number pattern files: The matched context displays the rows of [number], grep pattern1 | pattern2 files: show the rows matching pattern1 or pattern2, grep pattern1 files | grep pattern2: displays the rows matching both pattern1 and pattern2. Here are some special symbols used for searching: \ <and \> respectively mark the start and end of a word. For example, grep man * matches 'Batman ', 'manic', and 'man '. grep' \ <man '* matches 'manic' and 'man ', but not 'Batman ', grep' \ <man \>' only matches 'man ', not other strings such as 'Batman' or 'manic. '^': Indicates the first row of the matched string, '$': indicates the end of the row of the matched string,