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

25 thoughts on “How to delete an entire directory via SSH

  1. 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. Previously removing a magento installation via FTP = FAIL.

    Currently removing a magento installation via SSH = WIN.

    You sir, are a legend.

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

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

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

  6. ADD-ON
    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.