I came across an interesting task where I had to rotate several files in a folder - here is a quick bash script that can go into a specified directory and delete files older than 15 days.
-
#!/bin/sh
-
#---------------------------------------------------
-
# FILE ROTATOR SCRIPT
-
#
-
# The purpose of this script is to rotate and delete files
-
# greater than 14 days.
-
#---------------------------------------------------
-
-
# Vars
-
FILEDIR="/var/log"
-
AGE="15"
-
-
# Diagnostics
-
echo "Rotate starting..."
-
echo "Directory to search: $FILEDIR"
-
echo "File age to check $AGE"
-
echo " "
-
-
# Grep is used to ignore files with .
-
FILES_OLD=`find $FILEDIR -type f -mtime +$AGE -print |grep -v '^\.\/\.'`
-
echo "Files older than $AGE:"
-
echo $FILES_OLD
-
echo " "
-
-
# Deletes old images, notes and hashes.
-
echo "Deleting old files..."
-
#find $FILEDIR -mtime +$AGE -exec rm -f {} \;
-
echo "Rotate complete..."
Add new comment