Faustas - Programming, Projects, Psychology and Faust
The following shell script searches for files within a given folder and deletes the files that are older than x days.
# #!/bin/sh # FOLDER="/path/to/the/folder" DAYS=14 cd $FOLDER for i in `find . -maxdepth 1 -type f -mtime +$DAYS`; do rm `basename $i`; done
The variables FOLDER and DAYS can be used to adjust the script to your specific environment. You can use the FOLDER variable to specify the path where the script is searching for the files and the DAYS variable to declare the days back that should not be deleted.
The maxdepth parameter for the find function means that find only searches in the given folder and does not search in deeper levels. The mtime parameter is used to search for the files that were modified n*24 hours before the DAYS value.