HOWTO: Remove Directories in GNU/Linux
There are two options at your disposal to remove directories depending on whether you want to remove a single directory or an entire tree: rm -d or rmdir -p.
rm -d foo will remove the foo directory even if it is not empty. However, you must be root to use this command.
rmdir -p foo will remove the foo directory and ALL it’s subdirectories whether empty or not. You do not have to be root to do this, but you must own all the files and directories that will be effected.
Related Stories
POSTED IN: How To
8 opinions for HOWTO: Remove Directories in GNU/Linux
daveb
Apr 19, 2006 at 8:35 pm
rm -r foo
or rm -rf foo
if you’d rather not be prompted for every file in the directory.
Jon
Apr 19, 2006 at 8:37 pm
Thanks Dave! You’re right - I’d rather not be prompted :)
Geoff
Apr 24, 2006 at 1:46 am
Not to mention, you don’t have to be root to use them.
Jon
Apr 24, 2006 at 4:45 am
You only need to be root for the rm -d command.
Eric
Apr 28, 2006 at 7:33 am
I did not know rm -d and rmdir -p
I use rm -rf all the time
DOG
Feb 18, 2007 at 3:08 am
RM-D AND RMDIR-P DONT WORK
THANKS ERIC
Kyle
Feb 18, 2007 at 2:09 pm
@Dog: Try rm -R that stands for remove directory recursively and it will remove the directory and its entire contents.
Ben
Sep 21, 2007 at 2:22 pm
rmdir -p foo will _only_ remove foo and any subdirectories if they are _empty_ (http://www.linfo.org/rmdir.html). What is written above is incorrect.
Have an opinion? Leave a comment: