Take the 2-minute tour ×

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.


Yogi Yang

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The following script will do the trick:


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
add comment

Your Answer


