Linux: Text Wrangling
grep, pipes, and friends: find the needle in a gigabyte of logs.
Security work means reading a lot of text: logs, configs, scan output. Linux gives you small tools that combine into powerful one-liners.
1
Reading and searching
Command Use cat fileprint a whole file head -n 5 file/tail -n 5 filefirst / last lines tail -f filekeep printing new lines as they're written grep word filelines containing word grep -iignore case grep -vlines not matching grep -r word dirsearch every file in a directory grep -i "failed password" /var/log/auth.logpractice terminal · student@makooLogs are in /var/log. Try: grep, head, tail, wc -l, and pipes like grep Failed auth.log | wc -l
student@makoo:/var/log$2
Pipes
The pipe
|sends one command's output into the next command's input:cat access.log | grep " 404 " | wc -lThat counts the lines containing " 404 ". Useful pieces:
wc -lcounts linessortsorts lines,sort -nnumericallyuniq -ccollapses repeated adjacent lines and counts themcut -d' ' -f1keeps the first space-separated field
Top 5 IP addresses in a web log:
cut -d' ' -f1 access.log | sort | uniq -c | sort -rn | head -5
⚑ Report a problem with this room
Log in to report a problem.