Chapter 4: Linux Advanced Commands
Common Mistakes I See Students Make
Friends, these mistakes with advanced commands are costly on a live server – the config breaks, the service disappears after a reboot. Read them once and keep them in mind.
मित्रांनो, ॲडव्हान्स्ड कमांड्सच्या या चुका लाइव्ह सर्व्हरवर महागात पडतात – कॉन्फिग बिघडतो, सर्व्हिस रीबूटनंतर गायब होते. एकदा वाचून ठेवा.
दोस्तों, एडवांस्ड कमांड्स की ये गलतियाँ लाइव सर्वर पर महँगी पड़ती हैं – कॉन्फ़िग बिगड़ जाता है, सर्विस रीबूट के बाद ग़ायब हो जाती है. एक बार पढ़कर रखो.
- Editing before reviewing the candidate. Send transformed text to a separate path and compare its complete diff before applying it.
- Confusing a program’s permissions with its shell’s permissions. Identify which process opens the destination and verify that the writing path is authorized.
- Confusing runtime activity with startup installation. Inspect the unit’s activity, enablement, and expected activation separately.
- Testing the wrong listener or route. Verify the actual address, protocol, port, and request path. A loopback backend can belong behind a separate proxy.
- Treating a mount plan as current state. Compare the exact live mount and source with the intended entry. Validate a backed-up candidate without operating on unrelated mounts.
- Assuming a scheduled launch inherits your terminal’s context. Verify its interpreter, explicit paths, account, and time zone. Keep special table syntax out of a script’s formatting instructions.
- Changing permissions before identifying an interpreter error. Inspect the intended interpreter and line endings. Test a corrected copy before replacing an original file.
Trace a failure to the relevant layer
Start with the exact request the user made. Compare the service state, network path, and application settings. Then choose the next observation according to which of those boundaries is unverified.
A local listener, a reachable public front end, and the expected response are independent checks. The rehearsal below also compares the intended site's pre-change files with its candidate and with the separate library site.
Identify which assumption caused the mistake
A workshop maintenance ticket can say “replace the form address” while the machine has two web folders and several matching configuration copies. A practice report can say “nothing failed” while its input file was unreadable. A service can appear active while the request still goes somewhere unexpected. These mistakes have a common practical feature: the visible result answered a narrower question than the person thought it answered. Learn to connect each observation to the particular command and input that produced it.
Use a small audit record for a real change. It should identify the machine, account, working path, input, proposed output, expected result, and test to prove that result. The tools in this chapter already provide ways to inspect each item. Most of the work is deciding which facts are required. You can use a read-only command to test an assumption, then use a tiny local example to reproduce the difference before correcting a live workflow. A dry run should also identify where it stops. Seeing a list of proposed paths is valuable, while a completed change needs additional evidence about the applied content.
The examples below form a single scratch exercise. They use ordinary shell tools on a Linux or Unix-like practice machine, with Bash for the shell sections. They create only fictional Mauli workshop and neighboring library files under a generated directory. No external host, web daemon, mounted volume, system account, or package change is needed. As you proceed, write down one prediction before each command and compare it with the result. A useful practice result states the faulty assumption and the observed fact that corrected it.
| Visible symptom | Assumption to check | Narrow evidence |
|---|---|---|
| A text search matched extra rows | The pattern was literal and limited to the intended files. | Compare ordinary and fixed-string matches on known inputs. |
| A zero-count report looked successful | Every command in the pipeline read its intended data. | Check producer status and diagnostics as well as the count. |
| An edited file looks different | Only the planned setting changed at the approved path. | Review the candidate diff and compare unaffected fixtures. |
| A service says active | The application answered the same request the user made. | Check the listener, endpoint, and application response. |
| A scheduled job does not appear | The schedule clock and job environment match the terminal. | Check calendar conversion, dispatch, and actual script output. |
Limit the file set before matching text
The requester needs the one line that says the workshop's host name is mauli.example.test in its active file collection. The library site belongs to another scope. An archived copy of the workshop config belongs to the same tree but is not part of the active-file request. There is also a deliberately similar spelling without dots. This arrangement makes three possible mistakes individually observable: matching extra content, searching too many files, and treating a backup as active configuration.
review_lab=$(mktemp -d) || exit 1
printf 'Lab directory: %s\n' "$review_lab"
mkdir "$review_lab/workshop" "$review_lab/library" "$review_lab/workshop/history"
cat > "$review_lab/workshop/current.conf" <<'WORKSHOP'
site=mauli.example.test
example=mauliXexampleYtest
form=http://forms.example.test/daily
note=http://docs.example.test/help
WORKSHOP
printf 'site=mauli.example.test\n' > "$review_lab/workshop/history/retired.conf"
printf 'site=library.example.test\n' > "$review_lab/library/current.conf"
cp "$review_lab/library/current.conf" "$review_lab/library.expected"
Before issuing the full query, run two versions against the chosen current file. The first treats the dotted value as a regular expression. A period in that regular expression can match a character other than a period. The second treats the pattern as a fixed string. It additionally requires an entire line match with -x and includes the setting's key. Those choices express the requirement directly rather than relying on how similar a line looks on the screen.
printf 'Broad regular expression:\n'
grep -- 'mauli.example.test' "$review_lab/workshop/current.conf"
printf 'Literal full setting:\n'
grep -Fx -- 'site=mauli.example.test' "$review_lab/workshop/current.conf"
Broad regular expression:
site=mauli.example.test
example=mauliXexampleYtest
Literal full setting:
site=mauli.example.test
The quotes protect the pattern from being parsed by the calling shell. They do not tell grep which matching mode to use. The -F option supplies that choice. The -- marker ends option interpretation before the fixed pattern and path. This distinction carries to other utilities. A shell pattern such as a filename wildcard can be expanded by the shell before a tool opens a file, while a regular expression inside the tool has its own rules. Choose the parser deliberately and test both a known match and a tempting non-match.
To show the independent scope issue, list the workshop's matching config filenames with find. The first command traverses the workshop tree and includes the old file. The second prunes descent into the named history folder and uses a grouped expression to restrict the printed files. Sorting makes the examples easy to compare. These outputs are previews only, and the application ultimately decides which config files it reads. A real site can use an include rule that changes the active set. The exercise has given you that set explicitly.
(
cd "$review_lab/workshop" || exit 1
find . -type f -name '*.conf' -print | LC_ALL=C sort
printf 'Active-file preview:\n'
find . -type d -name history -prune -o \( -type f -name '*.conf' -print \) | LC_ALL=C sort
)
./current.conf
./history/retired.conf
Active-file preview:
./current.conf
Quote the filename pattern so find evaluates it for paths in the full traversal. Without the quotes the caller could expand the pattern using just its present directory. The first side of the final expression identifies a history directory and tells find not to descend. The alternative side can print matching regular files elsewhere in the selected tree. The command starts inside the workshop fixture, so it cannot wander into the separate library tree under the ordinary default link behavior. Do not replace a correct search location with a wildcard over the whole server to compensate for a matching mistake.
Distinguish no matching rows from an unreadable file
The second ticket is a status report. The writer ran a pipeline and saw a zero, so the email said no worksheets failed. The file name in the command was misspelled. A counting program that receives no lines can report zero successfully, regardless of why it received no lines. A report should distinguish a valid search with no matches from failure to read the source. Reproduce that distinction before changing the reporting command.
printf '%s\n' 'press-a passed' 'press-b passed' > "$review_lab/events.txt"
if grep -F -- 'failed' "$review_lab/events.txt"; then
printf 'Found matching event lines\n'
else
printf 'readable source grep status=%s\n' "$?"
fi
if grep -F -- 'failed' "$review_lab/missing-events.txt" 2> "$review_lab/search-error.txt"; then
printf 'Found matching event lines\n'
else
printf 'missing source grep status=%s\n' "$?"
fi
cat "$review_lab/search-error.txt"
readable source grep status=1
missing source grep status=2
The final line or lines from cat describe the missing path with wording from your grep implementation. They are omitted from the expected values. These are the typical grep statuses for this exercise. An ordinary match produces zero; no match on readable input produces one; the missing file produces an error status of two in GNU grep and the common versions used here. If an implementation reports another larger error value, keep the diagnostic and interpret it using that tool's documentation. Either way, the two cases are distinct even when both leave stdout empty.
Now read the same missing path through a test pipeline without hiding the diagnostic. The redirection on its first stage sends error text to a separate scratch file. The counter receives EOF and prints zero. Read the combined status and stage statuses immediately after the pipeline. The subshell deliberately limits the setting change to this exercise. This gives the exact numeric example that the mistaken report failed to distinguish.
(
set +o pipefail
cat "$review_lab/missing-events.txt" 2> "$review_lab/read-error.txt" | wc -l
printf 'pipeline status=%s stages=%s\n' "$?" "${PIPESTATUS[*]}"
)
cat "$review_lab/read-error.txt"
0
pipeline status=0 stages=1 0
As before the diagnostic is omitted above. The zero from wc is a count. The second line's first number is the combined Bash status with default last-command behavior. The stage values give the cat error and successful count separately. Enabling pipefail changes the combined result for this pipeline. The team still must decide what to do with legitimate nonzero statuses in other commands, such as grep's ordinary no-match result. A direct conditional check makes it possible to classify each branch before preparing a report. A dry run should include both a real zero case and a failed input case.
The error is useful even though the question concerns data. Do not hide all diagnostics to make a pipeline's display tidy. Keep results and errors separate until a person knows which one they want to inspect. Merging both into a stream intended for counting can turn a single error line into a count of one event. In the fixture a separate diagnostic file preserves what happened without contaminating the event output. In a live workflow, record the input time range and path alongside both kinds of evidence so a later reader can reproduce the same interpretation.
Review a candidate file before changing its destination
The approved change in this exercise is specific. Update the value of the exact active form line from HTTP to HTTPS in the workshop. Leave its note and the library site unchanged. The statuses and matching examples so far did not edit anything. Now create one new candidate separate from the current file. The pattern includes the key and anchors the line. The dots are escaped so a literal address is required.
sed 's|^form=http://forms\.example\.test/daily$|form=https://forms.example.test/daily|' \
"$review_lab/workshop/current.conf" > "$review_lab/workshop/candidate.conf.txt"
diff -u "$review_lab/workshop/current.conf" "$review_lab/workshop/candidate.conf.txt"
printf 'diff status=%s\n' "$?"
grep -Fx -- 'form=https://forms.example.test/daily' "$review_lab/workshop/candidate.conf.txt"
cmp "$review_lab/library.expected" "$review_lab/library/current.conf" \
&& printf 'Neighboring library fixture unchanged\n'
The diff normally displays one removed form line and one added form line, both at the active setting. It returns one for differences in the expected case. The following grep prints the intended new setting and the comparison confirms the library's known bytes. If the diff includes a note or the site label, stop and correct the expression. Use an ordinary shell for this expected difference test, or check diff in an explicit conditional if your shell exits on a nonzero command. Status greater than one conventionally describes a comparison problem rather than an ordinary content difference. The test is about scope, expected content, and the ability to compare, not just a normal-looking output file.
One easily missed mistake is redirecting the preview to its own input path. The shell can truncate the destination before sed reads it, while an in-place sed shortcut can replace the contents without a review. Use named paths that cannot accidentally resolve to the same file. On a live change, check if paths are links or if an include rule reads the candidate as another active config. A generated filename under a glob that loads every file of a certain type can affect configuration without an explicit promotion command. The training candidate ends in a different suffix to keep its role clear, but real include behavior must be checked against the actual application.
Privilege has a separate boundary. When a redirection follows a command, the calling shell handles the file open. Running a program with elevated privileges does not automatically elevate that shell's redirect. A tool such as tee can open its own output paths under the credentials of that tool. That distinction explains some permission errors, but permission to write does not authorize a production change. Start the exercise inside a user-writable directory. For a live site plan, verify the intended file and account, retain the original, check the proposed change through the application's documentation, and record how it is applied.
Verify what a backup can restore before relying on it
A common failure in a maintenance plan is treating the presence of an archive as approval to modify files. A useful backup must refer to the exact pre-change state. It should also be possible to find the required members and restore them to the path you intended. Our exercise has one original configuration and a separately prepared candidate. The backup contains only the original workshop configuration. The neighboring library file is deliberately outside that backup's scope because this change does not affect it.
tar -c -z -f "$review_lab/workshop-before.tar.gz" -C "$review_lab" workshop/current.conf
tar -t -z -f "$review_lab/workshop-before.tar.gz"
mkdir "$review_lab/recovery"
tar -x -z -f "$review_lab/workshop-before.tar.gz" -C "$review_lab/recovery"
cmp "$review_lab/workshop/current.conf" "$review_lab/recovery/workshop/current.conf" \
&& printf 'Restorable pre-change workshop file verified\n'
workshop/current.conf
Restorable pre-change workshop file verified
The tar name here is a relative member path under the original scratch parent. Extraction recreates that relative layout in a separate empty recovery directory. The comparison identifies the same original content before the change. If the archive contained library/current.conf instead, a successful integrity test would be insufficient. The backup would be valid as bytes while still missing the intended artifact. Record both the paths included and the expected bytes or known checks for recovery.
Simulate a change and rollback in the scratch workshop only. The file object here is an ordinary isolated configuration fixture, with no daemon attached. Apply the verified candidate and confirm the single expected address in the current file. Then copy the checked pre-change file back, verify the old address, and compare the library again. When applying a real change, use the service's reviewed procedure, which can include a parser check, an exact reload mechanism, and application probes. This is a file-state drill and stops before any live service step.
cp "$review_lab/workshop/candidate.conf.txt" "$review_lab/workshop/current.conf"
grep -Fx -- 'form=https://forms.example.test/daily' "$review_lab/workshop/current.conf"
cp "$review_lab/recovery/workshop/current.conf" "$review_lab/workshop/current.conf"
grep -Fx -- 'form=http://forms.example.test/daily' "$review_lab/workshop/current.conf"
cmp "$review_lab/workshop/current.conf" "$review_lab/recovery/workshop/current.conf" \
&& cmp "$review_lab/library.expected" "$review_lab/library/current.conf" \
&& printf 'Original workshop bytes restored and library bytes still match\n'
form=https://forms.example.test/daily
form=http://forms.example.test/daily
Original workshop bytes restored and library bytes still match
The two address lines reflect two different moments. Reading them without knowing when they were printed would make it look as though the file contained both. Keep operations and verification in their actual order when writing a ticket. For a real configuration sometimes the file alone is insufficient. The service might load included snippets, use a particular working directory, or retain the old running configuration after a failed reload. A backup and rollback should cover the actual change scope and use the documented path for applying it. Never restore all sites on a shared host simply to undo one file edit.
Write the real acceptance test as two positive assertions and one boundary check. First, the known old file is recoverable under the expected member name. Second, the candidate contains the exact updated value with the rest preserved. Third, the separate service's relevant file or response is unchanged. The order matters because the recovery evidence belongs to the state before applying the candidate. A newly generated archive taken afterward could restore the already changed file. The scratch drill establishes the relationship by comparing before, change, and restored bytes as separate events.
Archive size and timestamp are useful inventory fields, while the directory listing and restored content tell you what it actually contains. If someone passes you a file with the right name after a transfer, compare it to the recorded expected digest or content before using it for recovery. A general whole-machine archive might contain the right file somewhere and still make it difficult to restore only that one site. A scoped and verified restore map helps an operator choose exactly the intended path under pressure.
Follow the service, endpoint, and storage layers separately
Suppose a workshop operator inspects systemctl is-active and sees active, then declares a morning report available. The unit might be a successful oneshot that has already exited. The web service might be a different unit, or its worker could receive a request and return an error. Check the exact unit and its substate, then test the intended request and verify the content expected by the user. An active observation is about the unit's current runtime state. Enablement is a separate systemd installation relationship and does not prove the app starts successfully at the next boot. The correct next check depends on which state was actually requested.
Consider a report endpoint configured behind a reverse proxy. Its backend listens on 127.0.0.1:3000 and the proxy receives public traffic on another interface and port. A local request to the backend can succeed while a public request through the proxy fails. A rule allowing port 3000 on an EC2 network interface would not change the loopback bind. Check the intended architecture: the backend's local response, the correct virtual host and path on the proxy, and the route from the authorized client to the front end. Change only a boundary you have evidence is wrong. A local socket row, a reachable TCP address, and a correct HTTP response are distinct observations.
Use a similar comparison when a machine reports low disk space. The command df -h measures mounted filesystem capacity. The command du estimates space used by entries it can traverse. The result from lsblk says what block device and partition sizes are visible. Add findmnt --target to map the actual path into a mounted filesystem, and an exact mount-point query when a separate data device was expected. A directory can exist ready for a mount while still using root storage. If that unexpected state is the problem, using a recursive deletion to free the wrong filesystem can damage unrelated data.
A row in /etc/fstab describes part of a mount plan. It is not a live mount check. For a reviewed change, preserve the current configuration and check the source identity, type, and intended target using a candidate validation appropriate to the platform. Do not request mounts for every unrelated entry on a shared machine to test one new path. Verify the exact expected mount and its application dependency through the authorized operations. The fact that a candidate parsed successfully does not predict all boot conditions. It verifies a limited aspect of the plan.
Reproduce the scheduled command's context
The next mistake begins with a true observation: the command runs correctly when pasted into the terminal. In that terminal the student happens to be in the workshop directory. A scheduler or service process may start elsewhere, with a different search path and account. An unqualified name like current.conf can refer to a different directory or no file at all. Treat the working directory as an explicit dependency. If you cannot state it in the test notes, you cannot tell which command execution you reproduced.
The scratch fixture lets you compare two launches without starting a daemon. The first new Bash subshell changes to the workshop directory and runs a relative grep. The second runs from the generated parent directory with a clean environment, simulating an invocation that has neither the first shell's current path nor working variables. It redirects the failing diagnostic to a known private file so you can inspect it. Both small commands use read-only input tests.
(
cd "$review_lab/workshop" || exit 1
grep -Fx -- 'site=mauli.example.test' current.conf
)
(
cd "$review_lab" || exit 1
if env -i PATH=/usr/bin:/bin /bin/sh -c \
'grep -Fx -- "site=mauli.example.test" current.conf' 2> "$review_lab/launch-error.txt"; then
printf 'Unexpected successful relative lookup\n'
else
printf 'relative lookup status=%s\n' "$?"
fi
)
env -i PATH=/usr/bin:/bin /bin/sh -c \
'grep -Fx -- "site=mauli.example.test" "$1"' \
workshop "$review_lab/workshop/current.conf"
site=mauli.example.test
relative lookup status=2
site=mauli.example.test
The final test passes a known absolute file path as an argument to the explicit shell invocation. The word workshop is the command's chosen name, and the following argument is its $1. The surrounding shell preserves it as one path. This removes one working directory assumption and tests the meaningful output again. env -i does not impersonate a different user or emulate every scheduler setting. It isolates the inherited variable portion for this small test. A real job must still run with the correct access and launcher configuration.
Check calendar assumptions independently. If the goal is a daily 08:15 report in India Standard Time and the scheduler matches UTC, subtract five hours and thirty minutes to obtain 02:45 UTC on the same day. The calendar row would begin 45 2 * * * for that clock. That differs from setting the hour and minute as 8 and 15 on an unverified server. Where supported, an explicit scheduling timezone can instead document the intended local schedule. A log can use its own time zone. Use the clock named by the scheduler and record a known timestamp for the expected result. Do not change the clock of a machine other people use just to make one job's row easier to read.
Cron's parsing is another independent boundary. On Cronie, unescaped percent signs in the command are handled before a job's shell parses it, so a date format copied from a terminal can have unintended meaning. Keep the command in a reviewed script with an explicit interpreter and path. Test it outside the terminal's normal launch features as the intended account. A row saved successfully is evidence of the schedule setup, while a report of the correct contents and date is the proof of output. Read the dispatch and job logs separately when a report does not arrive.
Check identity and file scope before a wider change
A tempting reaction to a permission error is to apply a broad mode change so the command stops failing. First identify which process tried to open which path and with what permissions. The caller may have no access to a parent directory even though the final file's own mode looks readable. A script executed with bash file needs permission to read it; executing ./file also needs suitable execute permission and an available interpreter. A file using Windows line endings can cause the interpreter name to be parsed differently. These differ from an ordinary report output permission failure. Use the exact cause to choose the narrow change.
When a script exits with an interpreter error, inspect its first line with a byte-aware tool such as od -c and confirm the documented path exists on the executing machine. A carriage return shows as a different byte from a newline. Convert a copy with a suitable editor setting and test it before changing the original. This demonstrates two useful checks: confirm the syntax with the intended interpreter, then run the small known input and compare expected stdout, stderr, and status. A mode change cannot fix an invalid interpreter path, and changing line endings does not add an execute bit.
Similarly, do not assume that an interactive SSH account, the web worker, and a cron job are the same user. id -un describes the effective user of that command. A configurable environment label named USER can provide a different string and is unsuitable as proof of identity. Tools that can query a unit's configured user can help identify intended service context, while the runtime may also have privileges or restrictions defined by the service. Confirm the writer, the exact destination, and the permissions of that path rather than guessing by spraying changes over related directories.
For a site on a shared server, two document roots can contain files with identical names. The process account might have permission to write both even if the task covers only one. Mark the authorized root and the expected active configuration before planning a copy, archive, or rename. An exclusion based solely on a human-readable label can fail if a symlink or include points elsewhere. Identify the actual paths and compare the neighbor with known evidence when it is part of the acceptance criteria. A command that happened to complete need not have operated on the intended site.
Keep sensitive information out of the evidence itself. A full environment dump or an SSH verbose log can expose identifiers that the reviewer does not need. A filesystem scan can also display unrelated private paths. Save only the necessary values and checks, and redact fields whose contents are not required for the result. In this lesson all fixtures are fictional and the output can be compared directly. In a real handover establish which recipients may see details and test only the relevant part of the system.
Pass filenames as arguments and keep them inside the requested tree
Another source of overly broad work is treating a display of filenames as a list that can safely be split at every space or newline. Filesystem names can contain spaces, tabs, leading hyphens, and in ordinary Unix path components a newline. Those characters can be part of one filename. If the task is to inspect existing files, a list displayed for people and the argument list used by a machine need different representations. Preserve the filename boundary before adding a later operation such as copying or archiving.
Make a tiny selection test in its own folder. One name has a space, one begins with a hyphen, and one begins with a period. None is unusual data for this lesson. The first command prints the starting directory's normal glob selection. The second lets find identify matching regular files and pass them directly as distinct arguments to printf. All three names have the requested suffix, and all actions are read-only after the fixtures are created. Compare which files each mechanism selects rather than trying to repair the downstream output after it arrives.
mkdir "$review_lab/names"
printf 'test\n' > "$review_lab/names/shift notes.txt"
printf 'test\n' > "$review_lab/names/-extra.txt"
printf 'test\n' > "$review_lab/names/.retained.txt"
(
cd "$review_lab/names" || exit 1
shopt -u dotglob
printf 'Default shell glob:\n'
printf '<%s>\n' ./*.txt | LC_ALL=C sort
printf 'Find regular files by suffix:\n'
find . -type f -name '*.txt' -exec printf '<%s>\n' {} + | LC_ALL=C sort
)
rm -- "$review_lab/names/shift notes.txt" "$review_lab/names/-extra.txt" "$review_lab/names/.retained.txt"
rmdir -- "$review_lab/names"
Default shell glob:
<./-extra.txt>
<./shift notes.txt>
Find regular files by suffix:
<./-extra.txt>
<./.retained.txt>
<./shift notes.txt>
The shell's normal pattern does not include a leading period unless the pattern or a matching option includes one. The subshell disables the Bash dotglob option so that example has the expected behavior. Find's name test considers the hidden filename in this tree. The output shows the spaces kept in one displayed path, but the underlying safety comes from passing each filename as an argument. -exec ... {} + can pass multiple selected names to the command without producing an intermediate space-separated list. The prefixed ./ means the leading hyphen stays inside the path rather than appearing as the first character of an option word.
For a stream of filenames rather than direct arguments, a tool can use a zero-byte separator, as in find -print0 with a compatible reader. A null character cannot be part of a Unix filename, making the separator useful for exact machine processing. The readable line display in the lesson is adequate for these three controlled names, and would be ambiguous if a name contained a newline. Choose how to represent the names before sending them through a pipeline. A count of output lines would otherwise count the inserted filename line break as another entry.
Scope includes the behavior of links. A symbolic link named workshop/archive might point into a different location. Recursive operations differ in when they follow those links. Find's usual default behavior does not follow symlinks through a directory tree, while a deliberate follow-links option changes what it can visit. Some copying tools follow links during a recursive transfer under documented options. Decide whether a link itself or its target belongs in the policy before you run a traversal. In a shared host maintenance task, a scope description based on the spelling of the initial path can still be incomplete if the command follows external references.
When the request is only to inspect, preserve that boundary in your next step. First derive and print the exact candidate set. Then, if the authorized operation actually requires writing, review the same selection rules, verify that destination paths and identity match the intent, and apply the narrow change. A hand-written second command with a broader wildcard is a new selection and should be treated as a new operation. Even a previously inspected list can go stale when files change concurrently. In the private exercise, the generated paths remain the only actors. In a live environment, take suitable evidence about the current state before acting on it.
Catch summaries whose numbers are plausible but wrong
A different report has the right files and no execution error, yet it contains an incorrect tally. The training data has three failure rows, with the first and third belonging to the same station. The writer extracts station names and runs uniq with counts. That command joins adjacent identical values. It works exactly as directed, but repeats separated by a different station are separate groups. A report can fail its meaning even when every stage succeeds.
printf '%s\n' 'press-a failed' 'press-b failed' 'press-a failed' > "$review_lab/failure-fixture.txt"
printf 'Grouped in input order:\n'
awk '$2 == "failed" { print $1 }' "$review_lab/failure-fixture.txt" | uniq -c
printf 'Grouped by station:\n'
awk '$2 == "failed" { print $1 }' "$review_lab/failure-fixture.txt" | LC_ALL=C sort | uniq -c
Grouped in input order:
1 press-a
1 press-b
1 press-a
Grouped by station:
2 press-a
1 press-b
The spaces before counts vary by implementation. Both versions account for three total failure lines. If you check only that the counts sum to three, you can miss the duplicate station groups. A test should also assert one output row per station, and exact counts for the known fixture. That example teaches why a single aggregate total is a weak cross-check when the consumer needs correct categories. A sorting stage makes equal names adjacent for this task. A grouping program can alternatively accumulate values by an explicit key if the ordering or formatting requirements differ.
A similar problem appears when processing quoted comma-delimited export data. A shell field split can produce a confident total from the wrong field position when a quoted description contains its own separator. Inspect the input format and try a record whose structure exercises the edge case. Another case is trying to infer service health from a local HTTP success without checking the body. A different virtual host or default page can return a valid status and still be the wrong site. Those checks share a test design principle: build a counterexample where the broad success check passes and the real requirement fails.
Apply that design to the workshop scope case. A successful grep for the value alone could return a retired configuration. A successful diff could include two changes rather than one. A successful archive read could contain the wrong path. A successful reload could apply the intended file but leave a user route broken. For each operation state its narrower success and the additional evidence needed for the task. Keep the exact pre-change copy and independent expected results available long enough to evaluate both.
Finish a rehearsal and record the observations that mattered
For the first task, document the request as one input path set and one desired setting. Reproduce the two grep results and the two find previews. Then explain why a regex change cannot exclude the retired file and why limiting the directory set alone does not make a regular expression literal. Both remain independent parts of the search plan. A correct result has only the intended active file and the exact desired setting, with no mistaken match to the deliberately similar text.
For the second task, change the event fixture to contain one expected failure. Rerun the readable-source search and predict the new output and status. Then run the command against the deliberately missing file. Make two distinct handover rows for “found a failure” and “source unavailable.” For an additional test, restore the original all-pass fixture so you can demonstrate a valid zero at the same time. The command status and known fixture make these cases comparable without treating the printed count as the only evidence.
For the third task, repeat the candidate and rollback exercise. Before moving the approved file into place, compare the proposed diff with the stated change and verify the archived member name by listing it. Confirm that the required file can be extracted separately and that it matches the old bytes. After the exercise, check the original active setting and unchanged library file. Then write one line describing the additional application-level test you would need for a real server. The same test should have an actual host, path, method, and expected response defined before the change.
If a result surprises you, check the layer before rerunning. Search errors call for the exact file path and permissions. A different regex match calls for reviewing the pattern and mode. A wrong pipeline count calls for inspecting stage inputs and statuses. A missing scheduled artifact calls for checking dispatch, working directory, and report status. A live wrong response calls for route, identity, and application evidence. Keeping recovery notes precise helps someone else carry on without repeating already verified steps or changing unrelated settings.
Clean up only your generated scratch directory. Know which artifacts you made before you remove them. The commands below clear explicit paths and let rmdir protect unexpected files by refusing to remove a directory containing them. If you made a separate test copy, confirm its precise name and remove it separately. The workshop examples leave no running processes or installed jobs.
if [ -n "${review_lab:-}" ] && [ -d "$review_lab" ]; then
printf 'Cleaning exercise files in %s\n' "$review_lab"
rm -f -- "$review_lab/workshop/current.conf" "$review_lab/workshop/candidate.conf.txt" \
"$review_lab/workshop/history/retired.conf" "$review_lab/library/current.conf" \
"$review_lab/library.expected" "$review_lab/events.txt" "$review_lab/failure-fixture.txt" \
"$review_lab/search-error.txt" "$review_lab/read-error.txt" "$review_lab/launch-error.txt" \
"$review_lab/workshop-before.tar.gz" "$review_lab/recovery/workshop/current.conf"
rmdir -- "$review_lab/workshop/history" "$review_lab/workshop" "$review_lab/library" \
"$review_lab/recovery/workshop" "$review_lab/recovery" "$review_lab"
fi
unset review_lab
Explain why a convincing observation can still mislead
Interview question. How do you stop a small config edit from affecting a neighboring site?
Identify the exact configuration source and any active include paths. Prepare a separate candidate outside active loading, compare the complete diff, and retain a checked recovery copy of the affected site-specific files. Use an appropriate configuration validation and request test for the intended service. Compare evidence for unaffected neighbors when that is part of the change requirement.
Interview question. Why can a pipeline report zero with a successful default status for an unreadable file?
The reader can fail while the final counter successfully receives no lines and computes zero. Bash normally reports the final stage's status. Inspect the reader's diagnostics and status or use the appropriate failed-stage detection. Separately decide whether empty data from a successful read is valid.
Quiz. Quoting a dotted pattern still matches more lines than intended. Which test changes the matching semantics?
Use fixed-string matching if the dots should be literal, and add a full-line requirement when checking the exact setting. Quoting only controls how the shell passes the argument. It does not select grep's interpretation of that argument.
Quiz. A folder named data exists and is writable. Which observation tells you whether it serves the expected separate filesystem?
Look at the current mount point and expected source identity for that path. A directory can exist on the parent filesystem without the planned mount. Read the application's actual path and environment before concluding which storage it uses.
Quiz. An application behind a reverse proxy binds to loopback. Should a new inbound rule make the backend directly reachable?
A network rule does not change the local socket binding. Verify the intended front-end listener, proxy route, and backend response separately. A loopback bind can be the expected design for the backend when clients use the front end.
Revision cards
Check the intended scope
Record the path, account, target, and parsed pattern. Verify the scope before any edit or transfer.
Prove the artifact and its meaning
Inspect the result and independent expected values as well as command status. Test a counterexample where the weaker check passes.
Restore with evidence
List and extract the actual pre-change files into a separate location. Confirm their bytes before relying on the recovery procedure.
Primary references
- GNU grep selection modes and statuses
- GNU find expression and traversal semantics
- Bash syntax, redirection and pipeline behavior
- GNU sed substitution and output options
- GNU tar member names and extraction
- Systemd unit state and file installation checks
- Util-linux mount and target inspection
- Cronie calendar and command parsing rules