Home  >  Article  >  Operation and Maintenance  >  What is grep in linux

What is grep in linux

WBOY
WBOYOriginal
2022-03-16 16:15:587043browse

In Linux, grep is a command of the system. This command is the abbreviation of "global regular expression print" global regular expression output. It is used to find qualified strings in files. The syntax is "grep[ -abcEFGhHilLnqrsvVwxy]".

What is grep in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is grep in Linux

The grep command is the abbreviation of global regular expression print (global regular expression output). It is one of the most powerful commands in the Linux system. It searches one or more files for lines matching the given content and outputs the matching content.

The Linux grep command is used to find strings that meet the conditions in the file.

The grep command is used to find files whose content contains the specified template style. If the content of a file is found to match the specified template style, the default grep command will display the column containing the template style. If no file name is specified, or if the file name is - -, the grep command reads data from the standard input device.

grep syntax format:

grep [参数]

Common parameters:

  • -i: ignore case

  • -c: Only output the number of matching lines

  • -l: Only list matching file names, do not list specific matching lines

  • -n: List all matching lines and display the line number

  • -h: Do not display the file name when querying multiple files

  • -v: Display all lines that do not contain matching text

  • -w: Match whole words

  • -x: Match whole lines

  • -r: Recursively search the

test directory, the file contents are all the same:

What is grep in linux

Example 1. Search for the string

grep test test01.txt

grep -i test test01.txt#Ignore case

What is grep in linux

grep -n test test01.txt#-n displays line numbers

What is grep in linux

##grep -v 003 test01.txt#-v displays unmatched lines,

What is grep in linux

Related recommendations: "

Linux Video Tutorial"

The above is the detailed content of What is grep in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn