Online Linux Terminal Logo
OnlineLinuxTerminal
Traitement de texteCLI Manual

$grep

Rechercher des motifs de chaînes ou des expressions régulières dans des fichiers texte.

Syntaxe de la commandePOSIX Standard
grep [OPTIONS] PATTERN [FILE...]
Communauté Linux2.4k En ligne

Échangez avec des utilisateurs Linux, apprenez des commandes et téléchargez des PDF.

Essayer en direct dans le bac à sable interactif

Simulation côté client sans installation avec retour instantané.

Ouvrir dans le terminal plein écran ↗
bash — terminal

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 / OptionDescription
-iIgnore case distinctions in both patterns and input data.
-nPrefix each matched output line with its 1-based line number.
-vInvert the match to print lines that do NOT match the pattern.
-r, -RRecursively search all files under each directory.
-cSuppress normal output and print only the count of matching lines.
-EInterpret pattern as an Extended Regular Expression (ERE).

Exemples pratiques du monde réel

#1Search for errors in system log files
grep -i -n "error" /var/log/syslog

Searches /var/log/syslog for case-insensitive occurrences of "error" and prints line numbers.

#2Filter process list through a pipe
ps aux | grep nginx

Pipes process snapshot data and isolates lines containing the nginx web server process.

#3Count total failed authentication attempts
grep -c "Failed password" /var/log/auth.log

Outputs the integer count of failed login attempts without listing every individual line.