Introduction
Grep is one of the most powerful and widely used tools in the Linux environment for searching text within files or data streams. Its name comes from ‘global regular expression print’, although in practice we use it to locate simple or complex patterns using regular expressions. Learning to handle grep allows you to save time, filter logs, analyze code, and automate administrative tasks.
Basic syntax of grep
The simplest way to invoke grep is:
grep patrón archivo
Where pattern is the string or regular expression you want to search for and file is the target of the search. If you omit the file name, grep will read from standard input, allowing it to be combined with pipes.
Most useful options
- -i: ignores case.
- -v: inverts the match, showing lines that do NOT contain the pattern.
- -c: counts the number of matching lines.
- -n
This post is also available in ESPAÑOL.