$grep
Suchen Sie nach Zeichenfolgenmustern oder regulären Ausdrücken in Textdateien.
grep [OPTIONS] PATTERN [FILE...]Live im interaktiven Terminal ausprobieren
Client-seitige Simulation ohne Installation mit sofortigem Feedback.
Überblick & Funktionsweise
Grep ist das Standard-Unix-Werkzeug zum Durchsuchen von Textdateien und Logfiles mittels regulärer Ausdrücke.
Wichtige Optionen und Flags
| 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). |
Praktische Anwendungsbeispiele
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.
Verwandte Linux-Befehle
Durchsuchen Sie Verzeichnishierarchien nach Dateien basierend auf Name, Typ, Größe oder Änderungsdatum.
Dateiinhalte verketten und auf der Standardausgabe ausgeben.
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.