How do you remove a file in Linux?

Why Interviewers Ask This

This is a classic screening question for Linux / Shell Scripting roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

Use the rm command. rm filename deletes a file. rm -f filename forces deletion without prompting. rm -r dirname recursively deletes a directory and all its contents. rm -rf dirname is a common but dangerous combination — it force-deletes recursively with no confirmation. To remove an empty directory, use rmdir dirname. Always double-check paths before using rm -rf as there is no recycle bin — deleted files are gone immediately.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.