Show context lines grep
Print 3 lines before and 5 lines after each match
grep -B3 -A5 'FATAL' app.log
more grep
all 15 commands →
Count matches
grep -c 'POST /api' /var/log/nginx/access.log
Print only matched part
grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' access.log | sort -u
Invert match
grep -v '^#' /etc/nginx/nginx.conf | grep -v '^\s*$'
Search only in file type
grep -r --include='*.py' 'import os' /srv/app/
Exclude directories
grep -r --exclude-dir='.git' --exclude-dir='node_modules' 'TODO' .