$grep
Busque patrones de cadenas o expresiones regulares dentro de archivos de texto.
grep [OPTIONS] PATTERN [FILE...]Prueba en vivo en la terminal interactiva
Simulación del lado del cliente sin instalación y con respuesta inmediata.
Descripción general y funcionamiento
Grep es la utilidad estándar de Unix para buscar texto línea por línea mediante expresiones regulares en archivos y flujos de datos.
Opciones y banderas comunes
| Flag / Option | Description |
|---|---|
| -i | Ignore case distinctions in both patterns and input data. |
| -n | Prefix each matched output line with its 1-based line number. |
| -v | Invert the match to print lines that do NOT match the pattern. |
| -r, -R | Recursively search all files under each directory. |
| -c | Suppress normal output and print only the count of matching lines. |
| -E | Interpret pattern as an Extended Regular Expression (ERE). |
Ejemplos prácticos del mundo real
grep -i -n "error" /var/log/syslogSearches /var/log/syslog for case-insensitive occurrences of "error" and prints line numbers.
ps aux | grep nginxPipes process snapshot data and isolates lines containing the nginx web server process.
grep -c "Failed password" /var/log/auth.logOutputs the integer count of failed login attempts without listing every individual line.
Comandos de Linux relacionados
Busque archivos y directorios en una jerarquía según el nombre, tipo, tamaño o fecha de modificación.
Concatene e imprima el contenido de archivos en la salida estándar.
Output the first part (top lines) of text files.
Output the last part (bottom lines) of files or stream real-time logs.
Print newline, word, and byte counts for files.
Print text strings or write data to files using shell redirection.