Last active
October 6, 2023 17:46
-
-
Save wpscholar/23202ede09debb3bc713f2eeb82d900f to your computer and use it in GitHub Desktop.
How to use grep to lookup status codes in access logs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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[: ]" |
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
Also, how to use grep to search a directory:
grep "<search>" -nr .