Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Last active October 6, 2023 17:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpscholar/23202ede09debb3bc713f2eeb82d900f to your computer and use it in GitHub Desktop.
Save wpscholar/23202ede09debb3bc713f2eeb82d900f to your computer and use it in GitHub Desktop.
How to use grep to lookup status codes in access logs.
# Output the access log
cat access.log
# Run the results through grep to find any 500 status codes
cat access.log | grep "[: ]500[: ]"
# Find any non 200 status codes
cat access.log | grep -v "[: ]200[: ]"
# Find multiple status codes
cat access.log | grep -e "[: ]500[: ]" -e "[: ]405[: ]" -e "[: ]403[: ]"
# Exclude multiple status codes
cat access.log | grep -v -e "[: ]301[: ]" -e "[: ]302[: ]"
# Actively watch for non 200 status codes
tail -f access.log | grep -v "[: ]200[: ]"
@wpscholar
Copy link
Author

Also, how to use grep to search a directory:
grep "<search>" -nr .

@wpscholar
Copy link
Author

How to unzip a .gz log file: gunzip <file>.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment