Remove / Delete Directory and Its Contents in Linux

February 20, 2008 at 6:43 pm 31 comments

(Note: Please see my latest posts at my new blog!)

rm -rf <DirectoryName>

This command will remove a directory and its contents without prompting you to make sure you want to delete each file in the directory. Substitute <DirectoryName> with the actual directory name.

About these ads

Entry filed under: Linux. Tags: .

Computing Chi-Squared P-Value from Contingency Table in Python Filtering Data in Python (Example of Functional Programming Approach)

31 Comments Add your own

  • 1. shailesh  |  September 11, 2008 at 6:26 am

    Thanks.

  • 2. Adel  |  April 7, 2009 at 6:53 pm

    Thanks a lot

  • 3. NEWB  |  June 24, 2009 at 2:04 am

    to remove everything in a directory:

    rm -rf *

  • 4. syam prasad  |  October 8, 2009 at 6:04 am

    Very good useful information.

  • 5. abbaby  |  October 31, 2009 at 8:41 pm

    thx

  • 6. suni  |  May 30, 2010 at 12:48 pm

    i spent a hour on net before i get this info ………….

    thnks a lot !

  • 7. really  |  June 16, 2010 at 3:45 pm

    Really? I spent 2 hours…
    i tried rmdir but ididnt work.

    this work perfectly. thanks

    ul

  • 8. World Digital Datasets  |  September 15, 2010 at 6:05 pm

    Very handy…thank you

  • 9. Joe  |  February 7, 2011 at 8:52 am

    Thanks ! Helpful u !

  • 10. vflash  |  June 22, 2011 at 4:07 am

    great, ur site listed in number one google search results when i type “linux command remove directory and its contents”

    pretty good.
    Thanks

  • 11. Ofidz Al-akadarnya  |  July 7, 2011 at 3:53 pm

    Thanks for help.

  • 12. Madhuri Maddy  |  July 11, 2011 at 8:26 pm

    This is a very very dangerous command.. trust me I am telling you out of experience.. :(

  • 13. Steve  |  July 11, 2011 at 10:16 pm

    I agree, definitely. But when used carefully, it can save a lot of time. Also, never underestimate the importance of backups. :)

  • 14. dekfner  |  July 19, 2011 at 7:15 pm

    Yeah but every time you hit delete in Windows Explorer, you’re doing this same thing.

  • 15. steve88  |  August 22, 2011 at 7:24 am

    thx, btw you can rm -rf * too

  • 16. azli  |  November 15, 2011 at 3:01 am

    thanks, how to remove multiple folders and all the contents?

  • 17. Steve P  |  November 15, 2011 at 3:42 am

    You can delete multiple folders using wildcards. For example, if you had three directories called Dir1, Dir2, and Dir3, you could remove them with this commamd: rm -rf Dir*. But be careful!

  • 18. rama krishna  |  December 31, 2011 at 7:21 am

    its very helpful thanks

  • 19. parag1512  |  January 3, 2012 at 2:05 pm

    how can remove multiple dir by single command like if i have docs,music,pics three dir. so how can i remove all this by single command

  • 20. Steve P  |  January 4, 2012 at 2:50 pm

    Hi Parag,

    Yes, you can do something like this:

    rm -rf docs music pics

    Again, be very careful when you do this!

  • 21. sankeetha  |  February 16, 2012 at 4:25 am

    i was suffering a lot to remove the folder with rm -r as it prompted me for every file i had.
    i tried an hour with rm -r with th prompt last time. but this really helped me a lot… saved my timr.. thnks for the info.. thanks a lot……………….

  • 22. Mohsinkhan  |  March 15, 2012 at 8:43 am

    Thanks.

  • 23. thx  |  March 18, 2012 at 10:41 am

    thx

  • 24. Coupons  |  May 31, 2012 at 8:26 am

    Thanks a lot….

  • 25. sam  |  August 19, 2012 at 4:52 am

    This command only remove file forcely, not remove/delete directory.

  • 26. priya  |  July 24, 2013 at 6:43 am

    Thanks….

  • 27. Taati  |  October 24, 2013 at 9:53 am

    Thanks very helpful for me

  • 28. Remove / Delete Directory and Its Contents in Linux  |  November 30, 2013 at 9:14 pm

    […] February 20, 2008 at 6:43 pm   26 comments […]

  • […] Code Comments: Remove / Delete Directory and Its Contents in Linux […]

  • 30. Eray Aydın  |  April 13, 2014 at 12:00 pm

    Thank you, its works

  • 31. RM  |  April 15, 2014 at 12:05 pm

    Thank you. Very helpful

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed



Follow

Get every new post delivered to your Inbox.

%d bloggers like this: