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

Difficulty: Easy

Correct Answer: rm

Explanation:


Introduction / Context:
Deleting files is a frequent administrative and user task. Unix/Linux provides a simple command specifically for removing files and, with the right options, directories. Knowing the correct command—and its safety flags—prevents accidental data loss and improves scripting reliability.


Given Data / Assumptions:

  • You need to delete regular files from the command line.
  • Standard POSIX commands are available.
  • Basic usage suffices; recursive deletion is a related but separate option.


Concept / Approach:

The command to remove files is rm. By default it unlinks each file name. To remove directories and their contents, use rm -r (or -rf with caution). Other listed commands are either nonstandard or have different semantics: mv moves/renames files; del is a DOS command; remove is not a standard Unix command-line tool.


Step-by-Step Solution:

Delete a file: rm file.txtDelete multiple: rm file1 file2Delete by glob: rm *.log (use with care)Delete directories: rm -r dir/


Verification / Alternative check:

Run ls before and after rm to confirm removal. Use -i for interactive confirmation if safety is a concern.


Why Other Options Are Wrong:

  • remove: not a standard POSIX command.
  • mv: moves/renames; doesn't delete.
  • del: DOS/Windows command, not Unix.
  • None of the above: incorrect because rm is correct.


Common Pitfalls:

  • Using rm -rf / or similar destructive globs; always double-check paths.
  • Deleting files without permissions—prepend sudo if appropriate.


Final Answer:

rm.

Discussion & Comments

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