220-1102 Question 238
Single answercpA Linux technician needs to copy the file /home/analyst/report.txt to /var/backups/report.txt from a terminal session. The technician wants to preserve the original file and avoid changing its contents. Which command should the technician use?
- A
cp /home/analyst/report.txt /var/backups/report.txt
- B
mv /home/analyst/report.txt /var/backups/report.txt
- C
cat /home/analyst/report.txt > /var/backups/report.txt && rm /home/analyst/report.txt
- D
rsync --delete /home/analyst/report.txt /var/backups/report.txt
Show answer and explanation
Correct answer: A
Explanation
For a straightforward file copy in Linux, cp is the standard command. It copies data from a source path to a destination path and leaves the original file intact, which matches the scenario exactly. By contrast, mv relocates the file, and shell redirection combined with rm would also remove the source. While rsync is a valid file transfer and synchronization tool on many Linux systems, best practice is to use the simplest appropriate command for the task. Basic Linux command-line usage, including cp for copying files and directories, is a common A+ Core 2 objective area when working with operating system tools and terminal commands.
- A. Correct.
Correct. The cp command copies a file from the source path to the destination path while leaving the original file in place. In this scenario, it creates a copy of report.txt in /var/backups named report.txt without modifying the source file's contents.
- B. Incorrect.
Incorrect. The mv command moves or renames a file rather than copying it. Using mv here would remove the file from /home/analyst and place it in /var/backups, which does not meet the requirement to preserve the original file.
- C. Incorrect.
Incorrect. This command would copy the contents to a new file using shell redirection, but the appended 'rm' deletes the original file. That makes it functionally similar to a move, not a copy. A candidate might choose this if they know redirection can create files but overlook the requirement to keep the source file.
- D. Incorrect.
Incorrect. rsync can copy files, but the use of --delete is intended for synchronization scenarios and is unnecessary and potentially risky. It is not the best answer for a simple single-file copy task in an A+ Core 2 context. Also, rsync is more complex than needed when cp directly addresses the requirement.