grep 命令最基本的用法是在文件中搜索字符串(文本)。For example, to display all the lines containing the string bash from the /etc/passwd file, you would run the following command:例如,要显示/etc/passwd 文件中包含字符串 bash 的所有行,可以运行以下命令:grep bash /etc/passwd 输出应该是这样的:...
grep 命令最基本的用法是在文件中搜索字符串(文本)。 For example, to display all the lines containing the string bash from the /etc/passwd file, you would run the following command: 例如,要显示/etc/passwd 文件中包含字符串 bash 的所有行,可以运行以下命令: grep bash /etc/passwd 1. 输出应该是...
grep 命令最基本的用法是在文件中搜索字符串(文本)。 For example, to display all the lines containing the string bash from the /etc/passwd file, you would run the following command: 例如,要显示/etc/passwd 文件中包含字符串 bash 的所有行,可以运行以下命令: grep bash /etc/passwd 输出应该是这样...
This option ensures that only lines containing the exact wordserverare printed, along with the names of the files in which they are found. In this example, the output does not include lines containing the plural formservers. Search Subdirectories To recursively search all files, including subdire...
-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...
grep - print lines matching a patterngrep [OPTIONS] PATTERN [FILE...] grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
Find lines not containing pattern. A variation of a previous example: $ grep -vE "^#" /etc/ssh/sshd_config | grep "[[:space:]]" Include /etc/ssh/sshd_config.d/*.conf PermitRootLogin yes KbdInteractiveAuthentication no UsePAM yes X11Forwarding yes PrintMotd no AcceptEnv LANG LC_* Subsyst...
matchPATTERNwill be skipped.-L,--files-without-match print only namesofFILEs containing no match-l,--files-with-matches print only namesofFILEs containing matches-c,--count print only a countofmatching lines perFILE-T,--initial-tab make tabs lineup(ifneeded)-Z,--nullprint0byte afterFILE...
You can also use the zcat command to display the contents of a gz file and then pipe that output to grep to isolate the lines containing your search string. $ zcat file.gz | grep word-to-search Grep email addresses from a zip file ...
The exit status is 0 if selected lines are found, and 1 if not found. If an error occurred the exit status is 2. 即,grep 命令在所给文件中查找特定模式的字符串,可以提供多个文件名,在多个文件中查找。 如果没有提供文件名,则读取标准输入。