Problem Statement
What does the grep command do in Linux?
Explanation
Grep (Global Regular Expression Print) searches for patterns in text files and displays lines that match the pattern. It's one of the most powerful and commonly used text processing tools in Linux. Basic syntax is grep 'pattern' filename, which searches filename for lines containing 'pattern' and prints matching lines.
Grep supports regular expressions for complex pattern matching, making it incredibly versatile. Common options include -i for case-insensitive search, -v for inverse match (lines NOT matching), -r for recursive directory search, -n to show line numbers, -c to count matches, and -w for whole word matching.
Grep is essential for log file analysis, code searching, configuration file verification, and data filtering. It's often combined with pipes to filter output from other commands like ps aux | grep nginx to find nginx processes. Understanding grep is fundamental for efficient Linux command-line work and system administration.
