Module 1 · Linux: the 20 everyday commands · Lesson 4 of 16

Read and search: cat, less, grep, find

Show files, page through long ones, find the lines you need and the files you lost.

In this lesson · about 22 minutes

  • Show a file with cat and page through a long one with less
  • Search inside files with grep and its -i, -n, -c, -r options
  • Find files by name, type or size with find
  • Chain commands with a pipe (|) and save results with >

Key terms

Say the meaning to yourself, then tap a card to check.

grep in real life

Sam's shop app writes a log: one line per event. When customers say payments failed, Sam does not read 10,000 lines. He runs:

grep ERROR logs/app.log

and gets only the error lines. grep -i error also catches Error and error. grep -c ERROR just counts them. grep -r coffee ~ searches every file under the home folder.

Pipes: passing output along

The | key (pipe) sends one command's output into the next command, like a conveyor belt. cat logs/app.log | grep WARN gives the log to grep, which keeps the warnings. You will use pipes constantly: ps aux | grep python in the next lessons.

Saving output

> saves output to a file (replacing what was there), and >> adds it to the end: grep ERROR logs/app.log > errors.txt.

find

Put quotes around name patterns so the shell passes the star to find untouched: find ~ -name "*.log". Add -type f for files only or -type d for folders, and -size +10M for big files.

Practice terminal · missions

Investigate the payment problem

Customers complained that some payments failed this morning. Use the log to find out what happened.

Missions 0 of 10

  1. 1Print the short file notes.txt.
  2. 2Open logs/app.log in the pager.
  3. 3Show only the lines in logs/app.log that contain ERROR.
  4. 4Search again, ignoring upper or lower case and showing line numbers.
  5. 5Count how many lines contain ERROR.
  6. 6Send the whole log through a pipe to grep and keep only WARN lines.
  7. 7Save all ERROR lines into a new file called errors.txt.
  8. 8Search every file under your home folder for the word coffee.
  9. 9Find every file whose name ends in .log.
  10. 10Find files bigger than 10 MB.
sam@practice-box:~

Type a command and press Enter. Try help to list commands. Tab finishes names, ↑ repeats.

  • ~ (/home/sam)you are here
  • documents
  • budget-2026.csv
  • letters
  • thank-you.txt
  • meeting-notes.txt
  • resume.pdf
  • downloads
  • installer.zip
  • report-final-v2.pdf
  • report-final.pdf
  • logs
  • access.log
  • app.log
  • old
  • app-2026-09.log
  • app-2026-10.log
  • notes.txt
  • photos
  • beach.jpg
  • cat.png
  • trip
  • day1.jpg
  • day2.jpg
  • projects
  • website
  • index.html
  • style.css
  • scripts
  • backup.sh
  • hello.shruns
  • todo.md

This picture updates as you type. Changed items flash. runs = executable, a name badge = owned by someone else.

Check your understanding0 of 4 correct

Question 1

1.A 5,000-line log is too long for the screen. Which command lets you scroll and search it?

Question 2

2.Which command counts the lines containing 'timeout' in app.log, whatever the case?

Question 3

3.What does the | in ps aux | grep nginx do?

Question 4

4.You lost a file called invoice-77.pdf somewhere in your home folder. Which command finds it?

Quiz score: 0 of 4

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. The practice terminal is a simulation that runs in your browser: it imitates Linux (Ubuntu-style output) and Git closely, but it is not a real computer, and real output can differ slightly. The servers, people, web addresses and GitHub addresses in the labs are made up. Linux is a trademark of Linus Torvalds; Git and GitHub belong to their owners. Read-aloud uses your device's built-in voices.