Quickly Deleting Files on Linux
Posted by Johan Cyprich on 08 Apr 2009 | Tagged as: How To
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.
| Related posts: | |
|
|
Share this post:
Follow Me:
Did you find this post interesting and useful? You can keep up to date on this blog by subscribing to my RSS feed, or you can have new posts sent to you by e-mail. You can also follow me on Twitter.
2 Comments »
Tweet This Post!
















on 09 Apr 2009 at 12:28 pm 1.steve.lippert said …
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.
on 09 Apr 2009 at 4:12 pm 2.Johan Cyprich said …
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.