Basic file management on Linux/Unix Which command is used to delete (remove) a file from the filesystem?

Difficulty: Easy

Correct Answer: rm

Explanation:


Introduction / Context:
Every Unix/Linux user needs to manage files from the shell. Deleting files is a routine operation and is performed with a specific utility that removes directory entries. Knowing the correct command prevents confusion with copy, move, or rename operations.



Given Data / Assumptions:

  • The task is to remove a file (not a directory).
  • We are operating in a typical POSIX shell environment.
  • Permissions allow the deletion (write and execute on the parent directory).


Concept / Approach:

On Unix-like systems, rm removes directory entries for files. If the last link to a file is removed and no process holds it open, the storage is reclaimed by the filesystem. For directories, rmdir or rm -r is used. Options such as -i prompt for confirmation, -f forces removal, and -r recursively removes directories and their contents.



Step-by-Step Solution:

Identify the target: for example, notes.txt in the current directory.Run rm notes.txt to remove the file.Use rm -i notes.txt if you want an interactive confirmation.Verify deletion by listing the directory: ls.


Verification / Alternative check:

If the file persists, check permissions on the parent directory and confirm no alias or function overrides rm. Also verify that the filename is correct (quote paths with spaces).



Why Other Options Are Wrong:

  • rename: not a standard standalone command on all systems; renaming does not delete.
  • delete: not the POSIX-standard tool for removal.
  • cp: copies files; it does not remove them.
  • None of the above: incorrect because rm is the correct deletion command.


Common Pitfalls:

Using rm -r carelessly, globbing patterns that match more files than intended, or lacking proper backups. Consider rm -i or trash utilities for safety.


Final Answer:

rm

Discussion & Comments

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