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. rap says:

    This is workiiiiiing. Thanks.

  3. Dude says:

    Finally thanks!!!

  4. andre says:

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

  5. Dimitris says:

    Nice :) Kudos for this, have been googling it 😉

  6. Kraig says:

    It worked. Thanks.

  7. Humberto says:

    Totally worked, thanks so much!

  8. George says:

    LOVE IT ! Thanks guys !

  9. Tim says:

    Previously removing a magento installation via FTP = FAIL.

    Currently removing a magento installation via SSH = WIN.

    You sir, are a legend.

  10. Robbie says:

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

  11. Paul says:

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

  12. kristen says:

    thanks! googled it and found you 1st.

  13. Mayank says:

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

  14. Ciprian says:

    Thanks! Keep up the good work!

  15. Jon says:

    yes, thanks, worked perfectly!

  16. Jeff says:

    Cool, thanks bro.

  17. Dawn says:

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

  18. bachtiar says:

    kudos for this! 😀 you’ve safe my day :)

  19. Bethan says:

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

  20. Nathan says:

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

  21. 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!

  22. Xem phim says:

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

  23. 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! 😀

  24. 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 *