7 most common linux grep commands
Grep is a command-line utility that allows you to search for patterns in text files. Here are some common grep commands and their explanations:
grep pattern file
: This command searches the specified file for lines that contain the pattern.grep -r pattern directory
: This command searches the specified directory and all subdirectories for files that contain the pattern. The-r
option stands for "recursive."grep -v pattern file
: This command searches the specified file for lines that do not contain the pattern. The-v
option stands for "invert match."grep -i pattern file
: This command searches the specified file for lines that contain the pattern, ignoring the case of the characters. The-i
option stands for "ignore case."grep -c pattern file
: This command searches the specified file for lines that contain the pattern and prints a count of the number of matching lines. The-c
option stands for "count."grep -n pattern file
: This command searches the specified file for lines that contain the pattern and prints the line numbers of the matching lines. The-n
option stands for "line number."grep -l pattern file
: This command searches the specified file for lines that contain the pattern and prints only the names of the files that contain a match, rather than the matching lines themselves. The-l
option stands for "files with matches."