$grep
Поиск текстовых шаблонов и регулярных выражений внутри файлов и потоков данных.
grep [OPTIONS] PATTERN [FILE...]Попробуйте в интерактивной песочнице
Клиентская симуляция без установки с мгновенным результатом.
Обзор и принцип работы
Grep — стандартная утилита Unix для построчного поиска текста. Незаменима для анализа системных логов и фильтрации вывода команд.
Основные флаги и параметры команды
| 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). |
Практические примеры использования
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.
Похожие команды Linux
Поиск файлов и директорий в иерархии каталогов по имени, типу, размеру или дате изменения.
Чтение и объединение содержимого файлов с выводом в терминал.
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.