old-cache is an empty directory.
Remove only old-cache, relying on the empty-directory condition.
Which command is correct?
rmdir removes empty directories and fails when entries are present, making the condition explicit and safer than recursive removal.
Detailed explanation
rm old-cacheIncorrect. rm without a recursive option does not remove a directory.
Incorrect. rm without a recursive option does not remove a directory.
rm -rf old-cacheIncorrect. rm -rf removes contents recursively and is broader than required.
Incorrect. rm -rf removes contents recursively and is broader than required.
rmdir old-cacheCorrect. rmdir removes old-cache because it is empty.
Correct. rmdir removes old-cache because it is empty.
mkdir -p old-cacheIncorrect. mkdir -p creates a directory instead of deleting it.
Incorrect. mkdir -p creates a directory instead of deleting it.
Try it yourself
An example you can run in a temporary verification environment.
mkdir /tmp/kp-empty-dir && rmdir /tmp/kp-empty-dir && test ! -e /tmp/kp-empty-dir && echo REMOVEDExpected result
REMOVEDKey points
- rmdir removes empty directories only
- It fails when content exists
- The target is narrower than rm -rf
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.