Quick Linux Tip #85:
Question: How do I count error occurrences in Linux over time?
Try: watch -n 5 'grep -c "ERROR" /var/log/nginx/error.log'
Info: watch reruns commands at defined intervals (-n seconds) to track changing metrics. Coupling tail -f with awk increments and displays a live rolling tally as new log entries land.
Examples:
- $
watch -n 1 -d 'grep -c ERROR /var/log/app.log'# Highlight changing match values automatically - $
tail -f app.log | grep --line-buffered ERROR | wc -l# Count streaming lines without buffering lag - $
journalctl -f -u nginx | grep --line-buffered -c "ERROR"# Stream systemd journal logs live
Note: Add --line-buffered to grep when piping live streams to prevent stdio buffer delay. Use watch -d to visually highlight value differences between interval updates.
Leave a Reply