rm
is hardcoded to ask "interactively" (prompt waiting for user input) on write protected files. there are two methods to prevent rm
from asking:
rm -rf somedir
and
rm -r --interactive=never somedir
(both also work without -r
when deleting files instead of dirs)
explanation:
-f
makes rm
to "ignore nonexistent files and arguments, never prompt".
--interactive=never
does what it says: never be interactive. in other words: never prompt.
the difference between -f
and --interactive=never
is this part: "ignore nonexistent files and arguments".
compare:
$ rm -rf nonexistingname
$ echo $?
0
and
$ rm -r --interactive=never nonexistingname
rm: cannot remove 'nonexistingname': No such file or directory
$ echo $?
1
the difference is mainly interesting when writing scripts where you never want rm
to be interactive but still want to handle errors.
summary: on command line use rm -rf
. in scripts use rm -r --interactive=never
.
rm -rf
is the popular answer (and not wrong).rm -r --interactive=never
is the correct answer. technically correct. the best kind of correct.