How to delete an entire directory via SSH

I know this is probably common knowledge to Linux and Unix geeks. But every time I need to remove a directory with files in my NearlyFreeSpeech.Net SSH terminal I end up having to google for the command. So here it is for anyone else who’s out there googling!

rm -r -f YourDirectory

rm = remove / delete
-r = recursively deletes the directory and all files in it, including subdirectories
-f = will not ask for confirmation before deleting

This entry was posted in IT & Administration, Web & Software Development and tagged , , , . Bookmark the permalink.

25 Responses to How to delete an entire directory via SSH

  1. David Nunez says:

    geek tip: you can save another TWO WHOLE KEYSTROKES by doing “-rf” not “-r -f”

    you can usually stack single letter options if they have no modifer ‘-rfaweqkv’ but you cant stack the “-u cool -p beans” or “–fullword” options

  2. Dusty says:

    Good tip! 🙂

  3. rap says:

    This is workiiiiiing. Thanks.

  4. Dude says:

    Finally thanks!!!

  5. andre says:

    oh finallyyyyyyyyy.
    thank you so much. I’ve tried numerous dif things and only this has help. Its a load off thanks.

  6. Dimitris says:

    Nice 🙂 Kudos for this, have been googling it 😉

  7. Kraig says:

    It worked. Thanks.

  8. Humberto says:

    Totally worked, thanks so much!

  9. George says:

    LOVE IT ! Thanks guys !

  10. Tim says:

    Previously removing a magento installation via FTP = FAIL.

    Currently removing a magento installation via SSH = WIN.

    You sir, are a legend.

  11. Robbie says:

    I googled and I found. Therefore I am.
    Thanks for the tip for the non-linux geek.

  12. Paul says:

    Thanks man. I’m enjoying the power of SSH. saves me time.

  13. kristen says:

    thanks! googled it and found you 1st.

  14. Mayank says:

    Works! Thanks. but can anybody tell me why its slow.

  15. Ciprian says:

    Thanks! Keep up the good work!

  16. Jon says:

    yes, thanks, worked perfectly!

  17. Jeff says:

    Cool, thanks bro.

  18. Dawn says:

    Eternal gratitude – sometimes it seems the simplest things are the hardest to find answers to.

  19. bachtiar says:

    kudos for this! 😀 you’ve safe my day 🙂

  20. Bethan says:

    Thank you! So lovely not to have to read loads of tech-speak before finding the simple answer 🙂

  21. Nathan says:

    Hey, why are you on google’s top search results? It could be because you are awesome!
    TNX! helped me a lot.. 🙂

  22. andrux says:

    Well, not exactly via SSH but actually via the shell… not the same thing at all…

    And just in case, for those who might not know, be VERY careful with the -rf option, if you run it against your root directory you will end up in big trouble 🙂

    anyway, keep it up!

  23. Xem phim says:

    I have to delete many files. So its always disconnect before finished.
    what command to prevent it?

  24. China Mike says:

    Haha! And it is so coincidental that I TOO use NFSN as well! Just did a search for “SSH command to remove full directory” and this was the top one. EXCELLENT.

    I keep a file in a “my docs” folder in both Win and Linux (Ubuntu 11.10 currently) with a list of oft use linux commands because I really can’t recall them and I certainly don’t want to make a mistake with command line, especially if I do a dd type command! 😀

  25. China Mike says:

    Forgot to mention, when I am in Win XP I am using WinSCP and it’s a great “Commander” type interface, but I noticed when I deleted a WordPress directory within WInSCP it took FOREVER. I was sure doing it directly via SSH would be quicker, so next time I deleted a CMS directory I tried this method and VIOLA! Gone in 60 seconds.

Leave a Reply

Your email address will not be published. Required fields are marked *