Removing files on UNIX/Linux Which standard command removes one or more files from the filesystem?

Difficulty: Easy

Correct Answer: rm

Explanation:


Introduction / Context:
Deleting files is a frequent operation in UNIX/Linux. The shell provides a well-known command that removes files and, with appropriate flags, directories. Proper usage prevents accidental data loss and supports scripted cleanups in build systems and cron jobs.


Given Data / Assumptions:

  • You have permission to remove the specified files.
  • Wildcards may match multiple files; the shell expands them before rm runs.
  • Removed files typically cannot be recovered without backups or special tools.


Concept / Approach:
The rm command removes directory entries, effectively deleting files. Common flags: -i (interactive prompt), -f (force), -r or -R (recursive for directories), and -v (verbose). Always double-check patterns to avoid unintended deletions.


Step-by-Step Solution:
Remove a file: rm file.txtPrompt before each removal: rm -i *.logRemove a directory tree carefully: rm -r old_projectCombine force and recursive (use cautiously): rm -rf tmpdir


Verification / Alternative check:
List directory contents with ls before and after. Use trash utilities on desktop environments if you prefer recoverable deletions; rm bypasses a “trash can.”


Why Other Options Are Wrong:
erase (Option A) and delete (Option B) are DOS/Windows commands, not standard UNIX.dm (Option D) is not a removal command.None of the above (Option E) is incorrect because rm is correct.


Common Pitfalls:

  • Using sudo rm -rf with an incorrect path or extra space.
  • Forgetting quotes around patterns, causing the shell to expand unexpectedly.
  • Attempting to remove write-protected files without -f or proper permissions.


Final Answer:
rm

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion