CentOS Stream 9
Sponsored Link

Commands Help

Command :   Back to index

grep : print lines that match patterns
[SYNOPSIS] grep OPTION PATTERNS FILE
OPTION
-i ignore case distinctions in patterns and data
-n print line number with output lines
-v select non-matching lines
-w match only whole words
-x match only whole lines
-E PATTERNS are extended regular expressions
# grep -E 'word|test|test2' /home/test.txt
search for 'word' or 'test' or 'test2'
-F PATTERNS are strings
-G PATTERNS are basic regular expressions
-P PATTERNS are Perl regular expressions
-H print file name with output lines
-c print only a count of selected lines per FILE
-B NUM print NUM lines of leading context
# grep -B 4 http /etc/services
show results including the first 4 lines before the line where 'http' matches
-A NUM print NUM lines of trailing context
# grep -A 4 http /etc/services
show results including the last 4 lines after the line that matches 'http'
-C NUM print NUM lines of output context
# grep -C 4 http /etc/services
show results including 4 lines before and after the line that matches 'http'
-r search files in a directory for a pattern
# grep -r 'word' /home
display files that contain the 'word' in /home

Matched Content