Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .