Multiple choice technology operating systems

Which command is used to delete all files in the current directory and all its sub-directories?

  1. rm <dir name>

  2. rm -rf

  3. rm*

  4. rm -r *

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The command 'rm -r *' recursively removes all files and subdirectories from the current directory. The -r flag enables recursive deletion. 'rm -rf' would also work but requires a directory name argument. 'rm ' only removes a single directory. 'rm *' without -r won't delete directories.

AI explanation

'rm -r ' deletes all files and subdirectories in the current directory, recursively — the shell expands '' to every entry in the current directory, and '-r' tells rm to recurse into any directories among them, removing their contents too. 'rm -rf' alone, without any file or wildcard argument, does nothing (or errors as a missing operand) since rm needs a target to act on. 'rm ' only removes files matching one literal name, and plain 'rm' can't remove directories at all without -r. 'rm*' (no space) is a syntax error / would try to run a nonexistent command named 'rm*' with no arguments, not delete anything.