grep commands
15 commands, each with a one-line explanation. Click a command to copy it, or its title for details.
Commands 15 shown
-
grep -ri 'error' /var/log/Search all files under /var/log for 'error' (any case)
-
grep -B3 -A5 'FATAL' app.logPrint 3 lines before and 5 lines after each match
-
grep -c 'POST /api' /var/log/nginx/access.logPrint only the number of matching lines
-
grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' access.log | sort -uExtract IP addresses from log using Perl regex
-
grep -v '^#' /etc/nginx/nginx.conf | grep -v '^\s*$'Remove comment and blank lines from a config file
-
grep -r --include='*.py' 'import os' /srv/app/Limit recursive search to .py files only
-
grep -r --exclude-dir='.git' --exclude-dir='node_modules' 'TODO' .Search recursively skipping vcs and dependency dirs
-
grep -rn 'panic:' /var/log/app/Show file and line number for each match
-
rg 'TODO|FIXME|HACK' --type py -lList files containing TODO/FIXME/HACK in Python files
-
rg 'panic' -C3 --glob '*.go'3 lines of context around matches in Go files
-
rg 'secret_key' --hidden --no-ignoreSearch hidden and .gitignore'd files
-
rg 'old_value' --replace 'new_value' --passthru config.yamlPreview how a replacement would look without writing
-
rg 'error' /var/log/ --stats 2>&1 | tail -5Show total matches, files searched, elapsed time
-
grep -a 'password' /proc/<pid>/mem 2>/dev/null | strings | head -20Treat binary as text (-a) to search process memory
-
grep -E '(ERROR|WARN|CRIT)' app.log | tail -50Match lines containing ERROR, WARN, or CRIT
no commands match — try a different search