grep

15 commands

15 shown

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