Remove the temporary directory work and its files.
The directory was created by you and contains only writable regular files.
Which command specifies recursive removal?
rm -r recursively removes a directory and its contents. Confirm the target carefully because a wrong path can cause extensive damage.
Detailed explanation
rm workIncorrect. rm without -r does not remove a non-empty directory.
rmdir -p workIncorrect. rmdir removes empty directories and does not recursively delete files.
rm -d workIncorrect. -d is not the normal recursive directory-removal option.
rm -r workCorrect. rm -r work recursively removes the directory tree.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir "$tmp/work"; touch "$tmp/work/item"; rm -r "$tmp/work"; test ! -e "$tmp/work" && echo removed; rmdir "$tmp"Expected result
removedKey points
- -r means recursive
- rmdir requires empty
- Confirm the target path
Notes
- Environment: GNU coreutils 9.x / 自分が所有する一時ディレクトリ
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
Recursive removal is intentionally broad and should be limited to a path created for the test.
Check the side effect
Inspect variables and wildcard expansion before using a recursive deletion option.