220-1102 Question 239
Single answerrmA Linux technician is cleaning up an old user profile and needs to remove a directory named /home/jlee/archive along with all files and subdirectories inside it. The technician wants to complete the task from the command line in one step. Which command should they use?
- A
rm /home/jlee/archive
- B
rm -r /home/jlee/archive
- C
rmdir /home/jlee/archive
- D
del /home/jlee/archive
Show answer and explanation
Correct answer: B
Explanation
The correct command is rm -r /home/jlee/archive because rm with the recursive option is used to remove directories that contain files and subdirectories. In Linux administration and support tasks, this is a common command when cleaning up user data or old application folders. By contrast, rm without -r is intended for files, and rmdir is limited to empty directories. The del command belongs to Windows environments and would not be appropriate on a Linux system. As a best practice, technicians should verify the path carefully before running rm -r because it permanently deletes data without moving it to a recycle bin. This aligns with standard Linux command behavior documented in the rm and rmdir manual pages.
- A. Incorrect.
This is incorrect because rm without options removes files, not non-empty directories. If /home/jlee/archive contains files or subdirectories, this command will fail with a message indicating that it is a directory.
- B. Correct.
This is correct because the -r option makes rm recursive, allowing it to delete a directory and all of its contents in one command. This is the standard Linux method for removing non-empty directories from the command line.
- C. Incorrect.
This is incorrect because rmdir only removes empty directories. In this scenario, the directory contains files and subdirectories, so rmdir would not complete the task unless everything inside had already been removed.
- D. Incorrect.
This is incorrect because del is a DOS/Windows command, not the standard Linux command used in this scenario. A candidate might choose it by confusing Windows command-line syntax with Linux command-line tools.