UNIX Delete / Remove Directory Command

by on April 4, 2007 · 18 comments· LAST UPDATED April 4, 2009

in , ,

How do I delete / remove a directory under UNIX operating systems?

You need to use rmdir command to remove a directory. It will remove the directory entry specified by each dirname operand, which must refer to an empty directory.

For example, to remove a directory called "cppcode", enter:
rmdir cppcode

Note:
A directory must be empty before it can be removed. Use rm command to remove all files from a directory:
cd cppcode
rm *.cpp
cd ..
rmdir cppcode

You can also recursively remove directories and subdirectories. The directory will be emptied of files and removed using rm command:
rm -r oldletters

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 18 comments… read them below or add one }

1 kjgkd October 19, 2009 at 4:33 pm

Hi thanks..

Reply

2 neha April 6, 2010 at 12:51 am

Thank You

Reply

3 ashok kumar June 1, 2010 at 3:04 pm

thank u.I want more basic comends in unix

Reply

4 Sumit Jain December 16, 2010 at 12:23 pm

What are the other conditions for deleting/removing directories…….?

Reply

5 sathya January 28, 2011 at 6:41 am

Thanks

Reply

6 chester July 5, 2011 at 5:30 am

learning unix begins with deleting directories.

Reply

7 arun April 25, 2012 at 7:34 am

Nice

Reply

8 sunny August 3, 2011 at 4:50 am

The commands are well explained with proper example. Very helpful!!

Reply

9 Helloindia September 6, 2011 at 3:36 pm

Thanks.

Reply

10 Buki September 14, 2011 at 5:38 pm

Fantastic! Thank you!

Reply

11 Shoaib July 27, 2012 at 12:35 pm

Thanks !!

Reply

12 Kiruba October 3, 2012 at 6:27 am

Thanks. It works.

Reply

13 karan October 11, 2012 at 5:21 pm

if you do rm -fr cppcode, it will forcefully delete the directory(making it empty and delete).

Thanks,
KARAN

Reply

14 Guru October 14, 2012 at 2:14 am

It helped me :) thanks a tone :))))))

Reply

15 Harun R November 12, 2012 at 9:11 pm

You could also do a:

rm -rf

Reply

16 shahebaz April 2, 2013 at 5:38 am

thaks bt i want more

Reply

17 srinath April 19, 2013 at 1:57 pm

Thanks it works

Reply

18 Abhinandan June 10, 2014 at 7:10 am

thanks a lot..it solved my problem in a beautiful way

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous Faq:

Next Faq: