How to Remove an Entire Directory in Linux

To remove a directory in Linux, you use the rm command line command from a shell prompt with the -r argument to let Linux know to do a recursive delete where it delete all files including sub-directories and files in sub folders. Here is what you would enter into the command prompt to delete a directory named MyDirectory:

rm -r MyDirectory

You can also use the -f argument with the -r argument if Linux bothers you with a bunch of queries as to whether you want to delete certain files, but I found that it was not always necessary. When you find yourself having to type “yes” a thousand times however, use this command instead to stop it from asking you to confirm deletion:

rm -rf mydirectory

┬áDon’t Delete via FTP!

I found that when you need to clean up a server or delete hundreds, thousands or more files, using an FTP program like Filezilla becomes very inefficient. I found that logging into shell with Putty and using the above command, rm -rf mydirctory, works much faster and has way less problems. Definitely worth the extra time to log into a shell account!