UNIX file management: Which command removes (deletes) a file from the filesystem, permanently freeing its directory entry and disk space after the last link is gone?

Difficulty: Easy

Correct Answer: rm

Explanation:


Introduction / Context:
Deleting files is a core administrative skill on UNIX and Linux. Unlike some desktop environments that send files to a recycle bin, the rm command permanently removes directory entries. When no other hard links reference the inode and no process keeps the file open, the space is reclaimed.



Given Data / Assumptions:

  • You have a standard POSIX shell environment.
  • The task is deleting a file (not moving or renaming).
  • Permissions allow deletion (write permission on the parent directory is crucial).


Concept / Approach:

rm removes directory entries for files and directories (with -r for recursive). It does not ask for confirmation by default, so using -i is safer in interactive sessions. The actual data blocks are freed when no references remain, and the kernel updates filesystem metadata accordingly.



Step-by-Step Solution:

List files with ls to confirm the target name.Run rm filename to remove a single file.Use rm -i filename to prompt before removal (safer).Use rm -r directory to remove a directory tree; consider rm -rf with caution.Verify removal by listing the directory again.


Verification / Alternative check:

Run ls or find to confirm the file is gone. If a process had the file open, lsof can show open handles; space is reclaimed once handles close.



Why Other Options Are Wrong:

a: del is a DOS/Windows command, not standard UNIX.

b: mv moves or renames a file; it does not delete it.

d: remove is not the standard user command; rm is.

e: Not applicable because rm is correct.



Common Pitfalls:

Accidental use of wildcards, removing files as root without prompts, and attempting to delete without write permission on the parent directory. Consider aliases like rm -i to add a safety net.



Final Answer:

rm

Discussion & Comments

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