Pattern searching
grep searches files and command outputs for matching patterns.
Linux · Grep Command
Linux · Lesson
Master the grep command for searching text in Linux. Regular expressions and advanced usage. Practical examples for log analysis and troubleshooting.
The grep command is one of the most powerful Linux utilities used for searching and filtering text data.
It scans files or command outputs and displays lines that match a specified pattern.
Linux administrators frequently use grep for log analysis, troubleshooting, searching configuration files and processing command outputs.
grep searches files and command outputs for matching patterns.
It helps filter useful information from large amounts of text data.
grep supports regular expressions for advanced pattern matching.
The following examples demonstrate how to search and filter data using grep, egrep and fgrep commands.
Search for matching patterns inside files using the grep command.
Use the -c option to count the number of matching lines.
Use the -i option to ignore uppercase and lowercase differences.
Use the -n option to show line numbers with matching results.
Use the -o option to display only the matched part of the line.
Use the -v option to display lines that do not contain the pattern.
Use the -w option to match complete words only.
Use the ^ symbol to search for lines starting with a pattern.
Use the $ symbol to search for lines ending with a pattern.
Use extended regular expressions to search multiple patterns.
Search fixed strings without treating special characters as regular expressions.
root inside /etc/passwd.grep -c.grep -n.grep -v.grep -E.grep -F.In upcoming lessons, you will continue learning Linux text processing, regular expressions and shell scripting techniques.