Searching logs with grep
Everyday grep one-liners to find ERROR, ORA-, OutOfMemory and Java exceptions in a WildFly server.log for a given day and time window, count errors per hour, and filter /var/log/messages.
This page is a collection of commands. Copy and run them one at a time; do not execute the file as a script.
File: grep.txt
## Search for ERRORs only (Nov 27, between 11:00 and 13:00)
grep "ERROR" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27" | grep -E "11:|12:|13:"
## Search for ORA- (Oracle errors)
grep "ORA-" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27"
## Search for OutOfMemory
grep -i "OutOfMemory" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27"
## Search for SQLException
grep "SQLException" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27"
## Search for Java exceptions
grep -E "Exception|NullPointerException|ClassNotFoundException" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27"
## Count errors per hour
grep "ERROR" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27" | awk '{print $2}' | cut -d: -f1 | sort | uniq -c
## Save the result to a file
grep "ERROR" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27" > errors_nov27.log
## Show with context (5 lines before and after)
grep -B5 -A5 "SQLException" /home/appuser/wildfly/standalone/log/server.log.2025-11-27 | grep "2025-11-27"
## Search for "falha" (Portuguese for "failure") in messages (Dec 18, ISO format)
grep "2025-12-18" /var/log/messages | grep -i "falha"
grep "2025-12-18" /var/log/messages | grep -i "err: Guardium ATAP:"
## Search logs for the 5 minutes before 18:13 (18:08 to 18:13)
grep "2025-12-18" /var/log/messages | grep -E "19:0[8-9]|19:1[0-3]" | grep -i "err: Guardium ATAP:"
pstree -p | grep sync
systemctl list-timers --all
dmesg | tail -50