Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want a way to run Cron job (automatically daily) on server that will delete all files only (not folders) which are older than X days from today's date, in the public_ftp folder and all its sub folders to n level (Max depth).

My server provider is hostable.com.

TIA

Yogi Yang

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The following script will do the trick:

#!/bin/sh

find /path/to/folder/toclean -mtime +5 -type f -maxdepth 3 -exec rm -f {} \;

This assumes that the directory you wish to clean up is /path/to/folder/toclean, just replace it with your name. The command find -mtime +5 -type f finds all the files (-type f) which were last modified more than (+) 5 days ago, while -maxdepth 3 limits the depth of directory to search. The exec performs the actual removal.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.