≡ Menu

UNIX Delete / Remove Directory Command

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

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 20 comments… add one }

  • kjgkd October 19, 2009, 4:33 pm

    Hi thanks..

  • neha April 6, 2010, 12:51 am

    Thank You

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

    thank u.I want more basic comends in unix

  • Sumit Jain December 16, 2010, 12:23 pm

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

  • sathya January 28, 2011, 6:41 am

    Thanks

  • chester July 5, 2011, 5:30 am

    learning unix begins with deleting directories.

  • sunny August 3, 2011, 4:50 am

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

  • Helloindia September 6, 2011, 3:36 pm

    Thanks.

  • Buki September 14, 2011, 5:38 pm

    Fantastic! Thank you!

  • Shoaib July 27, 2012, 12:35 pm

    Thanks !!

  • Kiruba October 3, 2012, 6:27 am

    Thanks. It works.

  • karan October 11, 2012, 5:21 pm

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

    Thanks,
    KARAN

  • Guru October 14, 2012, 2:14 am

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

  • Harun R November 12, 2012, 9:11 pm

    You could also do a:

    rm -rf

  • shahebaz April 2, 2013, 5:38 am

    thaks bt i want more

  • srinath April 19, 2013, 1:57 pm

    Thanks it works

  • Abhinandan June 10, 2014, 7:10 am

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

  • Anand September 25, 2014, 4:51 pm

    rm -fr also removed forcefully.

  • avinash March 9, 2015, 11:58 am

    Is there any way to delete directory recurisively,,without deleting content of each directory .

Leave a Comment