Question 240
A Linux user needs to resolve this problem: A class uses mv file.txt /home/learner/archive/ and is surprised that the destination file name stays file.txt rather than becoming archive. What preventive habit belongs in the runbook?
Explanation
Correct Answer
Check whether the target directory exists before teaching move semantics. This practice reduces recurrence of the same problem. Technical reason: The destination path's directory-versus-filename interpretation determines whether mv relocates or renames an item. A controlled repeat test should show: The relocated file is found under archive/file.txt with its previous data intact.
Incorrect Answers
This safeguard maintains a different technical control: Require path validation and backups before any scripted recursive deletion. The recurring risk here is governed by: Check whether the target directory exists before teaching move semantics. The relevant review is “Check whether the target directory exists before teaching move semantics”.
“Preview glob matches before using them with destructive operations” is a sensible check for: Preview glob matches before using them with destructive operations. It is not the prevention measure for the current dependency: Check whether the target directory exists before teaching move semantics. The closer guardrail is “Check whether the target directory exists before teaching move semantics”.
The alternate safeguard protects a separate dependency: Teach touch behavior on existing files so timestamp updates are not mistaken for data changes. For this failure the continuing exposure is: Check whether the target directory exists before teaching move semantics. Maintain “Check whether the target directory exists before teaching move semantics” instead.