Introduction to grep command
grep is a command line tool originally used in Unix operating systems. Given a file list or standard input, grep will search for text that matches one or more regular expressions and output only matching (or unmatched) lines or text.
grep can query matching lines in the file based on the provided matching pattern list. After a matching line is found, the line content will be output to standard output (default). If other parameters are used, output in other formats can be generated
grep is used Matches text, which has no limit on the length of the input line except by available memory, and can match any character within the line.
Usage
grep -[acinv] 'Search content string' filename
Actual usage example
1. Search the log to see how many 503 errors there are
grep -c '503' /var/log/httpd/error_log-20141116
2. Search for lines containing the word error , and output the line number
grep -n 'error' /var/log/httpd/error_log-20141116
3. Search for lines without the word error, and output the line number
grep -nv 'error' /var/log/httpd/error_log-20141116
4. Search to find how many installed software versions there are
#centos下查看安装的Python版本 rpm -qa | grep -i python #Ubuntu下查看安装的Python版本 sudo dpkg -l | grep -i python
5. Filter the comment symbol #
#匹配 # 符号的行,但是输出的是 # 符号以外的行 grep -v '#' /etc/httpd/conf/httpd.conf
of the configuration file 6. Query each network card and IP address
ifconfig | grep -n inet
7. Ignore case search (-i)
grep -i "ErroR" log.txt
8. Search in all subdirectories (-r)
grep -r "exception" log.txt
9、精准全匹配搜索(-w)
grep -w "boo" /path/to/file
10. Accurate whole-word matching search for two different Word
grep -w 'word1|word2' /path/to/file
11. Count the number of occurrences of a string (-c)
grep -c 'word' /path/to/file #-n的话, 会在结果中,列出匹配字符串的序列号,并且会列出内容 grep -n 'word' /path/to/file
12. List only file names (-l)
grep -l 'main' *.pls
13. Highlight search results (–color)
grep --color apache /etc/passwd
grep regular expressions Shiyuan character set arrangement

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)
