If it can interest someone, the other day, i maked a little bash script to clean logs files on a production server (Debien here).
#!/bin/sh # Variables nbDays=2 # Number of days after you want to delete files password="your_root_password" # your password root currentDate=$(date +%s) deltaDays=$((86400 * $nbDays)) # Delete /Your/path/pattern_files for i in /Your/path/*form0_* do fileDate=$(date -d $(stat -c %y $i | cut -d' ' -f1) +%s) if [ $(expr $fileDate + $deltaDays) -gt $currentDate ] then echo -n $password | sudo -S rm $i fi done