cache contains files and subdirectories.
Remove cache and its contents recursively; a forced, confirmation-free deletion is not required.
Which command is appropriate?
rm -r recursively removes a directory tree. Because removal is difficult to undo, confirm the target path before using it.
Detailed explanation
rm -r cacheCorrect. rm -r removes cache and its nested contents recursively.
Correct. rm -r removes cache and its nested contents recursively.
rm cacheIncorrect. Plain rm does not remove a non-empty directory.
Incorrect. Plain rm does not remove a non-empty directory.
rmdir cacheIncorrect. rmdir refuses a directory that contains entries.
Incorrect. rmdir refuses a directory that contains entries.
rm -f cacheIncorrect. -f forces file removal but does not provide recursive directory traversal.
Incorrect. -f forces file removal but does not provide recursive directory traversal.
Try it yourself
An example you can run in a temporary verification environment.
mkdir -p /tmp/kp-rm-tree/sub && touch /tmp/kp-rm-tree/sub/file && rm -r /tmp/kp-rm-tree && test ! -e /tmp/kp-rm-tree && echo REMOVEDExpected result
REMOVEDKey points
- -r means recursive
- rmdir is for empty directories
- -f is not the recursive option
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.