Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

In bash all I know is that

rmdir directoryname

will remove the directory but only if it's empty. Is there a way to force remove subdirectories?

share|improve this question

2 Answers 2

up vote 59 down vote accepted

The following command will do it for you. Use caution though.

rm -rf directoryname
share|improve this answer
"-f" is "--force" which overrides some sanity checks and prompting. A safer command to start with would be rm -r directoryname. – Jim Paris Aug 17 '12 at 3:35
For some reason I get a rm: invalid option -- r error when trying to delete a directory with rm -r <directoryname>. – Sunspawn May 26 at 15:58

if rm -rf directoryname fails you, try using rm -R -f directoryname, or rm --recursive -f directoryname.

If you are not having any luck with these, you should consider reinstalling rm or switching shells.

share|improve this answer
These were the options available on my rm man page, I looked it up by typing man rm to view my options on recursive deletion and the force options. – saterHater Nov 11 at 18:38
Does your rm man page list -r?  What does it do?  (Try it in a directory that you create just for testing purposes, with only dummy files (and maybe subdirectories) in it.)  What operating system are you using? – G-Man Nov 11 at 19:08
P.S. If rm -r doesn't work, that would be an OS issue, not a shell issue. (Strictly speaking, it would be an issue with the version of rm that you're using, so you could address it by installing a different version of rm, or searching your system to see whether you already have a different version of rm in some directory other than /bin.) – G-Man Nov 11 at 21:34
Ah, right. I forgot to mention I'm on Ubuntu 14.04 When I ran man rm in my terminal, it gave me a text file with the less text viewer. I scrolled found an indented entry with a whole that had the -R and --recursive options cozied up with the -r option, signifying that all of those arguments are identical. – saterHater Nov 11 at 22:38
edit: have you tried sudo rm -r directoryName? The unwritten rules of the basic commands is that -r will allow a program to run recursively on every file your filesystem (starting where ever you choose!) and that -f will forcefully do things, even if it's dangerous. 'cd', 'mv', 'ls' mostly holds this principle true. ls -r / is gonna be a duzie, and cp -rf / /dev/null will destroy everything on your filesystem. <--Never run that command! – saterHater Nov 11 at 22:49

protected by Community Nov 11 at 22:49

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.