This note collects small shell patterns for inspecting logs, comparing configuration files, and narrowing failures.
tail -n 100 service.log
grep -n "ERROR" service.log | tail -n 20
grep -n "WARN" service.log | tail -n 20This gives a quick view of recent activity and the latest error locations.
When a line number matters:
nl -ba service.log | sed -n '240,280p'When a pattern matters:
grep -n -C 3 "connection refused" service.logUse -C for surrounding context, -A for lines after a match, and -B for lines before a match.
diff -u app.conf app.conf.newLook for:
- changed ports or addresses
- changed file paths
- changed feature flags
- missing comments that documented assumptions
- whitespace-only changes in sensitive formats
For directory comparisons:
diff -ru config.before config.afterls -l app.conf
stat app.conf
file app.confThis catches simple problems:
- wrong owner
- unexpected permissions
- symlink surprises
- binary or encoded content where plain text was expected
{
date
hostname
echo "Recent errors:"
grep -n "ERROR" service.log | tail -n 20
echo
echo "Config diff:"
diff -u app.conf app.conf.new
} > troubleshooting-report.txtThe useful habit is to keep evidence, commands, and conclusions close together.
- Inspect before editing.
- Copy or version-control important config before changing it.
- Prefer
diff -uover memory when reviewing changes. - Avoid pasting private hostnames, IPs, tokens, or logs into public notes.