Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Sep 28 '10 at 14:01

This question came from our site for professional and enthusiast programmers.

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.

share|improve this answer
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". – agporwfnz29 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
share|improve this answer
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.

share|improve this answer

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
share|improve this answer

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 ;-)

share|improve this answer

You must log in to answer this question.