Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Sep 28 '10 at 14:01

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

5 Answers 5

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

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
1  
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
1  
@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". –  bytesum Sep 28 '10 at 14:10
4  
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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.