$grep
Rechercher des motifs de chaînes ou des expressions régulières dans des fichiers texte.
grep [OPTIONS] PATTERN [FILE...]Essayer en direct dans le bac à sable interactif
Simulation côté client sans installation avec retour instantané.
Aperçu et fonctionnement
Grep est l'utilitaire standard Unix pour analyser et filtrer du texte ligne par ligne à l'aide d'expressions régulières.
Options et drapeaux courants
| 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). |
Exemples pratiques du monde réel
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.
Commandes Linux associées
Rechercher des fichiers et des répertoires dans une arborescence selon le nom, le type, la taille ou la date.
Concaténer et afficher le contenu des fichiers sur la sortie standard.
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.