Need a cron job to delete files and subdirectories

Discussion in 'Content Management' started by Decipher442, Oct 11, 2011.

  1. #1
    I'm looking for a cron job that will delete files and sub-directories within a directory on a daily basis...

    Example:
    www.mysite.com/directory/ <-- the cron job is made to delete all files and sub-directories created inside this sub-directory on a daily basis.
    www.mysite.com/directory/file1.php <-- deleted daily
    www.mysite.com/directory/1/ <-- deleted daily

    I would use this cron but i think it only deletes the files with in the directory and doesnt delete the sub-directories..
    find /directory -maxdepth 1 -type f -mtime +7 -exec rm -f {} \;
    Code (markup):
     
    Last edited: Oct 11, 2011
    Decipher442, Oct 11, 2011 IP
  2. borgy

    borgy Active Member

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #2
    Try to increas the maxdepth parameter to 3 or 4
     
    borgy, Oct 20, 2011 IP