Quickly Deleting Files on Linux

By on April 8, 2009

Once in a while I need to delete all of the files and folders on my Linux hosting account. This is usually due to updating an application, installing a new web application, or more often installing a clean application in my testing folder.

I would normally use WinSCP, but the problem with deleting files through this is that when there are thousands and files and folders, the process could take a long time. Deleting a Joomla installation, for example, takes more than 30 minutes to do.

A faster way to delete files is to go into your shell account (assuming your web host allows you to have one), and from the root directory, enter the following command:

rm –r folder

This will recursively delete all items in the folder and then delete the folder itself. If the folder is a subdomain, then recreate it using the rmdir command. This process takes seconds as opposed to the method used in WinSCP.


2 comments on “Quickly Deleting Files on Linux

  1. While this is a quick way to remove an entire directory in linux you really must take caution in using it.

    I always go with the full path to remove directories
    rm -Rf /var/www/vhost/subdomain.cyprich.com
    instead of
    rm -Rf subdomain.cyprich.com

    which may be correct if I am in /var/www/vhosts, but would be wrong if I am in say my home directory.

    I have borked a dev system by running rm -Rf in /etc instead of in /tmp like I wanted to do.

    It’s a rookie mistake I admit, but something that can also be learned from.

  2. Hi Steve. corykrug on Twitter said you can recursively delete all files and directories with

    rm – rf *

    Its probably a good idea giving a full path when deleting files just to be safe.

Leave a Reply

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

%d bloggers like this: