READDEMOGUIDED LABINDEPENDENT LABQUIZREVIEW
Module 3 of 7 · 30 min Reading and searching text
Beginner · 2/5Written by CoreQ Academy (drafted with AI assistance). Awaiting review by Sean Ofodile.
You will be able to- Read logs with head, tail and grep
- Chain commands with pipes
- Summarise data with sort, uniq -c, cut and wc
Pipes
The | character sends one command's output into the next command's input. Small tools combine into powerful ones.
$ cat access.log | cut -d " " -f 1 | sort | uniq -c | sort -rn | head -3grep finds lines
grep PATTERN FILE prints matching lines. -i ignores case, -v inverts the match, -c counts and -o prints only the matching part.
Counting what matters
sort | uniq -c | sort -rn is the classic "top N" pattern: group identical lines, count them, then rank by count.
Why logs are protected
Auth logs reveal usernames and attack patterns, so they are readable only by root and the adm group. Use sudo and expect to be audited for it.
Demo: try these in the terminal
head -n 3 /var/log/nginx/access.log | peek at the format |
grep 404 /var/log/nginx/access.log | find failed requests |
cut -d ' ' -f 1 /var/log/nginx/access.log | sort | uniq -c | sort -rn | rank clients by request count |
sudo grep -c "Failed password" /var/log/auth.log | count failed logins |
Quiz
Knowledge quiz · pass mark 80%
- Which command shows the last 20 lines of a file?
- Order the pipeline that ranks repeated lines from most to least common.
- sort -rn
- sort
- uniq -c
- Count lines containing ERROR in app.log.$
- In a space-separated log, how do you print only the first field?
- From the lab auth log, which details make 203.0.113.45 suspicious? (choose all)
- What does | do?
- Which grep option shows lines that do NOT match?
- A regular user can usually read /var/log/auth.log without sudo.