C

Linux › Module 5 › Lesson 2

BeginnerModule 5Lesson 2/5

grep, head, tail, and wc

Search and slice text with grep, head, tail, and wc

15 min+40 XP3 quiz
Module progress2 of 5

Opening

Logs are huge. Your eyes are not.

Servers generate thousands of lines per hour. grep finds needles in haystacks. head and tail show the start or end. wc counts lines, words, or bytes. Together they are log analysis 101.

1. grep — Search Text

grep pattern file grep "error" app.log grep -i fail auth.log — case insensitive grep -r "password" /etc/ — recursive (careful!) grep -n "root" /etc/passwd — show line numbers

2. head and tail

head file.txt — first 10 lines head -n 20 file.txt — first 20 tail file.txt — last 10 lines tail -f auth.log — follow live log (great during incidents)

3. wc — Count

wc -l file.txt — line count wc -w file.txt — word count wc -c file.txt — byte count

Combine them

grep "Failed password" /var/log/auth.log | tail -20 Shows only the twenty most recent failed login attempts.

Knowledge Check

1

grep is used to:

Multiple choice

Knowledge Check

2

tail -f is especially useful for:

Multiple choice

Knowledge Check

3

wc -l counts:

Multiple choice

← Previous

Answer all 3 knowledge checks to continue. (0/3 answered)