Linux Delete Directory With rmdir Command

by on September 5, 2007 · 16 comments· LAST UPDATED December 13, 2009

in , ,

I'm new to Linux and I'd like to know how to delete directory under any Linux distributions?

You need to use the command called rmdir. It remove empty directories.

rmdir command syntax

mdir [OPTION] {directory-name}

Delete / remove directory

To delete directory called foo, enter:
rmdir foo

Remove DIRECTORY and its ancestors

For example remove directory structure sales/99/march
rmdir -p sales/99/march

Recursive delete

Remove all directories and subdirectories, use rm command with -r option:
rm -rf /home/data/2000

Please note that rmdir command works with all Linux and Unix like operating systems. For more information read rm and rmdir command man pages:
man rm
man rmdir

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 16 comments… read them below or add one }

1 Zootropo September 6, 2007 at 7:20 am

You can also use rm -rf


2 Chandrabhanu Mahapatra October 16, 2007 at 8:15 am

It,s quite helpful here,but you should be more precise.


3 lakshmikanthan May 30, 2008 at 5:40 am

This is very useful for me


4 Kamal June 4, 2008 at 8:41 am

Thanks a lot. Thins really helped me.


5 Scott January 6, 2009 at 3:38 pm

rm -rf /home/data/2000
removes all directories AND files recursively. Option -f means force i.e. to do it without prompting.


6 DNA February 11, 2010 at 8:21 am

rm [options] files | directories

The rm (remove) command can delete files:

$ rm file1 file2 file3

or recursively delete directories:

$ rm -r dir1 dir2 dir3

Some Useful Options:

-f “Forces the deletion ignoring any errors or warnings.
-i “Asks before deleting each file”
-r recursively removes a dir(s) and it’s content(s). Use with extreme caution, especially if combining it with the -f option!

You can also use the rmdir command:

The rmdir (remove directory) command deletes one or more empty directories you name.

To delete an entire directory path (Use with extreme caution!) use the -p option along with the directory path (not just the directory name):
rmdir -p dir1/dir2/dir3

The above example would delete not just dir3, but dir1 & dir2 as well!

This will delete dir1,dir2 & dir3!


7 kasun January 21, 2011 at 10:31 pm,s really worked.


8 Yogendra February 22, 2011 at 4:54 am

Thanks & hats off to ur knowledge buddy


9 velocirapt0r November 25, 2011 at 3:25 pm

I weep for the future of Linux users if this considered praise-worthy.


10 Hans April 9, 2011 at 6:10 am

What a wanker! You instruct people to delete the entire file path without warning them? Nice try sir. I wonder how many systems you helped break.


11 velocirapt0r November 25, 2011 at 3:24 pm

I rm -rf all the time O.o
Sure, I know people who have lost work to it, but it’s so inefficient to go through potentially a lot of prompts…


12 Mathew waller December 10, 2013 at 12:43 pm

Think common sense comes into play if your not sure how a command works do not use it until you are sure…i wouldn’t fly a plane on instructions given to me by someone i don’t know….would you?


13 riesal September 21, 2011 at 8:41 am

how to delete folder named \ ?


14 velocirapt0r November 25, 2011 at 3:29 pm

Generally speaking (depending on what shell you’re in – BSH, CSH & BASH should be fine), a “\” is an escape character, which means it transforms special characters (“\” included) into string literals. So running “rm -rf ./\\” would recursively delete a directory in the current directory by the name of “\”. Hope this helped.


15 Iqbal Sajid March 5, 2012 at 9:09 am

I wanted to copy all files from one folder to another but leaving all folders that started with S, so i used command:

cp -R [!S]* /NewFolder/

and it seems it is doing what i wanted. i’ll update here (InshahAllah) when finished copying ..


16 shashank August 4, 2013 at 2:47 pm

plz tell me …if we make a directory/file in the root …than how we delete it when we are login from a local user …..


Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: