Module 2: Text and logs
Search logs with grep
When something breaks at 2 a.m., the answer is usually in a log with thousands of lines. grep prints only the lines you ask for.
● Runs 100% in your browser. Nothing here can harm a real system.
Step 1 of 8
Find a word
grep prints the lines containing some text: first what to look for, then where.
Your task
Find the lines with ERROR in logs/app.log.
guest@ohsudo: ~ — Ubuntu 24.04
Starting the terminal…
What you'll practice
- Find a word.
grepprints the lines containing some text: first what to look for, then where. - Ignore case. grep is case-sensitive, so
ERRORmisseserror.-iignores case. - Count them.
-cprints how many lines match, instead of the lines themselves. - Exclude the noise.
-vreverses the search: it prints the lines that don't match. - Line numbers.
-nadds the line number, which helps you find the place in a file, or in an editor. - Search a whole folder.
-rsearches every file in a folder, and prints which file each line came from. - One word or another.
-Eallows extended patterns, where|means "or". Quote the pattern, or the shell treats|as a pipe. - Failed logins. Logins are recorded in a log only root can read. On Debian and Ubuntu it's
/var/log/auth.log. Logins are recorded in a log only root can read. On RHEL, Rocky and AlmaLinux it's/var/log/secure, notauth.logas on Debian and Ubuntu.