SI Learning
0% read · Practice is tracked separately
← My learning
Version 1 · Chapter 5Reading mode

Find the right file and the actual change

By the end: Separate searching filenames, searching contents, and comparing versions.

The idea

Choose the search space first. find examines paths, grep examines text, and diff explains changes. Quote patterns so the shell does not expand them before the intended program sees them. Run the lab to create the example files.

Your command toolkit

find

What it solves: Search a directory by file properties.

bash
find . -type f -name '*.txt' -print

The quoted glob is evaluated by find. Start with -print and review matches before adding any action that changes files.

locate

What it solves: Find indexed paths quickly.

bash
locate notes.txt

Results come from a periodically updated database and may be stale. plocate and mlocate are common implementations.

grep

What it solves: Find matching lines with context.

bash
grep -n 'ERROR' events.log

-n includes line numbers. A no-match exit status is 1; it does not by itself mean the command failed to read the file.

which

What it solves: Locate an executable on PATH.

bash
which ls

Useful for external programs. In Bash, command -v and type also understand functions, aliases, and builtins, so they are better for explaining shell resolution.

whereis

What it solves: Find related binaries and manuals.

bash
whereis ls

Searches known locations for binaries, sources, and manual pages. It is not a complete filesystem search.

diff / sdiff

What it solves: Review line-by-line differences.

bash
diff -u before.txt after.txt
sdiff before.txt after.txt

diff -u shows a patch-style view; sdiff places versions side by side. Exit status 1 means differences were found, not a processing error.

cmp

What it solves: Check whether bytes are identical.

bash
cmp before.txt after.txt

Reports the first difference. No output with status 0 means identical bytes; use this when text formatting is irrelevant.

Before you move on

Try the guided lab below. Compare the result with the explanation, then record your reasoning in the workbook. A missing optional program or a restricted environment is something to explain, not a reason to change system settings blindly.

Practice with evidence

  1. Predict the result
  2. Run the guided lab
  3. Compare the output
  4. Explain your choice

A worked example

Guided lab

bash
si_lab=$(mktemp -d)
cd "$si_lab" || exit
printf 'status=ready\n' > before.txt
printf 'status=done\n' > after.txt
printf 'INFO start\nERROR timeout\n' > events.log
find . -type f -name '*.txt' -print
grep -n 'ERROR' events.log
diff -u before.txt after.txt

What to expect: Two .txt paths, ERROR on line 2, and a diff showing ready replaced by done. diff returns 1 because these files differ.

Make it yours: Write one filename search, one content search, and one comparison. Explain why a nonzero exit code needs to be interpreted for the specific command.

Read further

Apply what you learned

Your private practice

Why quote '*.txt' in a find expression?

Answers are private. Completion requires the correct knowledge-check answer and a written response when an activity is included.

Restore a downloaded workbook

Choose a recovery file for this course and version. Review the recovered copy before saving it to your account.

Ask a question or report a problem

Describe what needs attention. Your private answer is shared only if you select the option below.

All learning paths
SI CENTRALIZATION · LEARN

Linux Command Line: from first command to confident practice

24 chapters · Your own pace

0 of 24 chapters complete