Apple Terminal
Read-only, can be slowSearch a Log for Errors With Context
A local log contains too many lines to manually scan for the relevant failure.
Command
grep -n -C 2 'ERROR' ./app.log
Before you run this
System impact: Read-only. Can create load on large logs, directories, filesystems, or process tables.
When not to use it: Do not use it for structured JSON analysis when jq would be more precise.
Expected output
Matching ERROR lines with two lines before and after each match.
System impact
Read-only, can be slow. Nothing changes. The command prints matching lines with line numbers and nearby context.
Scope this to the smallest useful path or service on busy systems.
Recovery / rollback: no state is changed.
When to use it
Use when debugging build logs, app logs, export logs, or CLI output saved to a file.
When not to use it
Do not use it for structured JSON analysis when jq would be more precise.
next steps
Related commands
Watch a Log or Build File Update
Need to see whether a file is still changing? Let tail follow it live.
tail -f ./app.log
Show Context Around the First Error
The line before the error often explains the error.
grep -RInC 3 -m 1 'ERROR' artifacts logs
Scan Every CI Log for Error Lines
One grep pass can turn a log pile into a failure list.
grep -RInE 'error|failed|failure|exception|traceback' artifacts logs | head -50
Flush macOS DNS Cache
Changed DNS but your Mac still visits the old place? Flush the resolver cache.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Stop the Process Blocking a Dev Port
Free a stuck dev port without hunting through Activity Monitor.
lsof -ti tcp:3000 | xargs kill
Study mapping
Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.
Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.