On Unix/Linux systems, which command is used to remove an empty directory from the filesystem?
-
Ardir
-
Bremove
-
Crd
-
Drmdir
-
ENone of the above
Answer
Correct Answer: rmdir
Explanation
Introduction / Context:Managing directories from the shell requires specific commands. Unlike removing files, removing directories safely ensures that filesystem structure is not corrupted. There is a specific command in Linux for deleting empty directories.
Given Data / Assumptions:
- The directory is empty (contains no files or subdirectories).
- We are using a Unix/Linux shell with standard GNU coreutils.
Concept / Approach:
The rmdir command removes directories, but only if they are empty. For non-empty directories, rm -r is needed. Using the correct command prevents accidental recursive deletions.
Step-by-Step Solution:
Create test: mkdir testdirRemove: rmdir testdirError if not empty: 'Directory not empty'Use rm -r testdir for forced recursive deletion if needed.Verification / Alternative check:
Check with ls before and after removal. rmdir will fail on directories with contents, which is expected behavior.
Why Other Options Are Wrong:
- rdir: not a valid Linux command.
- remove: command does not exist in standard Unix.
- rd: DOS/Windows command, not Linux.
- None: incorrect because 'rmdir' is correct.
Common Pitfalls:
- Confusing 'rmdir' with 'rm -r'; rmdir only works for empty directories.
- Using DOS-style 'rd' on Linux, which will not work.
Final Answer:
rmdir.