Remove old files

Head Surfer
October 9th, 2008

Server cleanup and management is a very important task. Clients often store old files or emails in a folder on the server. The following command will allow you to locate old files on the server and automatically remove them if they are greater than X days old.

find /home/backups/example -name “*” -ctime +14 | xargs -r rm

Here’s the breakdown of the command.
find /home/backups/example = look in the /home/backups/example folder.
-name “*” = look for all files – if you wanted specific files like zip only files you would change this to:
-name “*.zip” = that would tell the command to only locate files that are in that folder and end in *.zip
-ctime +14 = this is in days. So you’re telling it to find anything that is older than 14 days.
| xargs -r rm = this is the actual action. This tells the server to locate the files that match the conditions from above and then remove them from the server.

Warning: This is not Microsoft Windows. There is no “are you sure” or recycle bin. Once you run this command it will start removing the files immediately.

How To Host A Website is a Web Hosting Review service. We provide web hosting reviews for best hosting, server hosting, cheap hosting and more as we answer the most important website hosting question - How To Host Website pages successfully.

Words visitors used that found this page online:

Disclosure: We are a professional review site that receives compensation from the companies whose products we review. We are independently owned and the opinions expressed here are our own. Please contact us if you would like your web hosting company considered for a web hosting and support review.
Back to top Copyright 2012 © How To Host A Website, An OS Hosting, LLC Company