In Unix/Linux file management, which command is used to remove (delete) one or more files from the filesystem?

Difficulty: Easy

Correct Answer: rm

Explanation:


Introduction / Context:
Removing files safely and correctly is a fundamental shell skill. The standard POSIX command for deleting files is short and powerful, supporting interactive prompts, recursive removal for directories, and forceful deletion when required. Knowing the right command prevents confusion with DOS/Windows terminology.


Given Data / Assumptions:

  • We are operating in a Unix-like shell (bash, zsh, etc.).
  • Target objects are regular files (not necessarily directories).
  • Standard GNU coreutils or equivalent are available.


Concept / Approach:
The command 'rm' removes directory entries for files. Common switches include '-i' for interactive confirmation, '-f' to force and ignore nonexistent files, and '-r' (or '-R') to recurse into directories. Deletion is immediate; recovery relies on backups or snapshots, so caution is advised, especially with wildcards and elevated privileges.


Step-by-Step Solution:

Delete a single file: rm file.txtDelete multiple files: rm *.logPrompt before each removal: rm -i *.confRemove a directory tree: rm -r old_project/ (optionally add -i)


Verification / Alternative check:
Run 'ls' after the command to confirm the files are gone. For critical data, simulate first with 'echo rm ...' to ensure globbing expands as expected before committing the real removal.


Why Other Options Are Wrong:

  • erase/delete: DOS/Windows commands; not standard on Unix.
  • dm: Not a standard deletion command.
  • None of the above: Incorrect because 'rm' is the correct Unix command.


Common Pitfalls:
Using 'rm -rf /' style destructive commands, forgetting that 'rm' does not use a trash can, and not quoting filenames with spaces or special characters.


Final Answer:
rm

Discussion & Comments

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