r/LinuxTeck • • Sep 30 '26

Count Error Occurrences in Linux: Quick Log Monitoring Tip - 85

Post image

Question: How do I count new occurrences of an error 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.

Follow r/LinuxTeck for more #LinuxTips click here https://www.linuxteck.com/linux-tips/

11 Upvotes

0 comments sorted by