Automatically pruning aged files


I have a few security cams around my house that are monitored by a motion-detection/recording application (SecuritySpy). This program uploads Quicktime movies and jpegs to an ftp site. This allows me to download pictures and videos off the web when my tweaked-out neighbors come over and steal concrete out of my driveway. (Crazy! I know. But that is their way.) I also like the idea of having off-site retention in case they break in and swipe my computer. The video doesn’t use that much space – it ran for 8 months and never reached the 200GB quota I set up for that account.

Anyway, Dreamhost is now billing me – something about being “backup/non-web” content. It’s not that much money for a couple of months’ retention but, I still want to limit the amount of space used. Setting up a quota just sends me an email – I still have to manually delete the old files. I would like to set up a cronjob that prunes my files based on age.

So, my question is: Can anybody suggest a script or a command that will automatically prune the files based on age? I saw a reference to in the Dreamhost Wiki but couldn’t find the script.

Because I am not *nix native, writing the script is beyond me. However, I think I can figure out how to set up the cronjob.

Thanks in advance.


The find command works well for these sorts of things.

If you want to remove all files older than 300 days from directory xyz and all subdirectories of xyz:

find /home/user/xyz -Btime 300 -exec rm {} ;

“man find” from the command line will give you a description of the find command and all of its options.


Thanks for the assist. You put me on the right track.

I had to modify the command a little:

Dreamhost requires the full paths.

-Btime is not support on the DH shell. It works on my Mac but, DH has an older version of the find command. Replaced with the legacy command: -mtime +300

The rm command returned an error because the directories cannot be deleted unless empty (fortunately). Added the qualifier to limit the search to files only: -type f

For the edification of any other users who may need this, here are the two commands that worked best in the SSH shell:

/usr/bin/find /home/.myDHservername/myftpusername/Security_Spy -mtime +3 -type f -print

/usr/bin/find /home/.myDHservername/myftpusername/Security_Spy -mtime +3 -type f -exec rm {} ;

Notes: ‘-print’ lists the found files instead of deleting them (a good idea if, like me, you don’t know what you are doing).
Until I’m sure the cronjob is working I’ve limited the retention to 3 days.
Individual camera sub-directories inside ‘Security_Spy’ are searched recursively and files are removed.

So, I’m setting up the cronjob now. In a few days we’ll see how it works.

Again, thanks for your help.


Works great, increased the retention to 60 days:

/usr/bin/find /home/.myDHservername/myftpusername/Security_Spy -mtime +60 -type f -exec rm {} ;