# Linux rm non-interactive command

I want to delete a directory with its files and I want to do that as follows:

rm -r dirToDelete\


Unfortunately, I always get asked for EACH single file if I want to delete this because it is write protected. Is there a way to suppress this feedback message so that just the whole directory with its contents disappears?

• rm -rf is the popular answer (and not wrong). rm -r --interactive=never is the correct answer. technically correct. the best kind of correct. – lesmana Apr 18 '18 at 10:53

A lot of distros alias "rm" to "rm -i". Personally, I think that's the stupidest idea ever, so first do a "alias rm" to see if that's the case, or just verify if "/bin/rm" behaves differently. If it is, look in /etc/profile, /etc/profile.d, /etc/bashrc or your own .profile or .bashrc to see where it's set and remove it.

• Might be an idea to elaborate /why/ it's stupid, for example, that doesn't add the same protection against accidential use to, for example, system calls that delete files, other programs that also delete files, and so on. – Arafangion Sep 28 '10 at 14:01
• @Arafanion: Foremost this is a bad idea because if you are used to the interactive behavior you can screw up easily on other hosts with sane "rm". – user16115 Sep 28 '10 at 14:10
• The main reason it's stupid is that it changes the default behaviour of a standard command. So either rm doesn't work the way you expect it because it's interactive, or it stops working the way you expect it when you go to another system because you started expecting it to be interactive. – Paul Tomblin Sep 28 '10 at 14:25

You want rm -rf.

From the rm man page:

-f, --force
ignore nonexistent files, never prompt
• You probably also want super-user or ubuntu. – Kendrick Sep 28 '10 at 13:53
• @Kendrick you might also want to do --no-preserve-root on Ubuntu as well, just to be safe </sarcasm>. – Nitrodist May 11 '11 at 16:00

Add -f e.g. rm -rf dirToDelete - but be careful to get the directory name right.

Note: this question isn't really programming related so really should be asked on superuser instead.

rm asks for confirmation because it's aliased to rm -i. To bypass the alias for a single command, add a backslash in front of the command:

\rm -r dirToDelete


For rm, you can also cancel out the -i with a -f:

rm -rf dirToDelete


I hope that rather soon distros which do

alias rm='rm -i


switch to

alias rm='rm -I'


from the man page:

-I     prompt once before removing more than three files, or when removing
recursively. Less intrusive than -i, while still giving protection
against most mistakes


I suggest you modify your .bashrc to still protect you from mistakes ;-)

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`.