grep
15 commands
15 shown
Recursive case-insensitive search
Search all files under /var/log for 'error' (any case)
grep -ri 'error' /var/log/
Show context lines
Print 3 lines before and 5 lines after each match
grep -B3 -A5 'FATAL' app.log
Count matches
Print only the number of matching lines
grep -c 'POST /api' /var/log/nginx/access.log
Print only matched part
Extract IP addresses from log using Perl regex
grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' access.log | sort -u
Invert match
Remove comment and blank lines from a config file
grep -v '^#' /etc/nginx/nginx.conf | grep -v '^\s*$'
Search only in file type
Limit recursive search to .py files only
grep -r --include='*.py' 'import os' /srv/app/
Exclude directories
Search recursively skipping vcs and dependency dirs
grep -r --exclude-dir='.git' --exclude-dir='node_modules' 'TODO' .
Print filename and line number
Show file and line number for each match
grep -rn 'panic:' /var/log/app/
ripgrep fast search
List files containing TODO/FIXME/HACK in Python files
rg 'TODO|FIXME|HACK' --type py -l
ripgrep with context
3 lines of context around matches in Go files
rg 'panic' -C3 --glob '*.go'
ripgrep search in hidden files
Search hidden and .gitignore'd files
rg 'secret_key' --hidden --no-ignore
ripgrep replace preview
Preview how a replacement would look without writing
rg 'old_value' --replace 'new_value' --passthru config.yaml
ripgrep stats
Show total matches, files searched, elapsed time
rg 'error' /var/log/ --stats 2>&1 | tail -5
Search binary files
Treat binary as text (-a) to search process memory
grep -a 'password' /proc/<pid>/mem 2>/dev/null | strings | head -20
Extended regex alternation
Match lines containing ERROR, WARN, or CRIT
grep -E '(ERROR|WARN|CRIT)' app.log | tail -50
no commands match