Created
January 4, 2021 13:57
-
-
Save ByronScottJones/5e87f99e1284fb7e39cd57f2ae59e347 to your computer and use it in GitHub Desktop.
Clean Folders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Days | Folder | |
---|---|---|
1 | FolderPath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
Folders="clean-folders.csv" | |
while read line | |
do | |
#Get the folder path and the number of days to expire files for that folder | |
days=$(printf "$line" | awk -F',' '{gsub(/\"/,""); print$1}' ) | |
folder=$(printf "$line" | awk -F',' '{gsub(/\"/,""); print$2}' ) | |
#printf "Days: '$days' Folder: '$folder'\n" | |
RE="^[0-9]*$" # REGEX Pattern to check for a whole number | |
#If the Days is not a Whole Number | |
if [[ ! $days =~ $RE ]] | |
then | |
#Skip the Header Line | |
printf "Skipping Header: $line\n" | |
else | |
#Get the number of files to be deleted | |
count=$(find $folder -mtime +$days | wc -l | sed 's/ //g') | |
printf "Deleting $count files in '$folder' that are more than $days days old:\n" | |
find $folder -mtime +$days -print -delete | |
fi | |
done < $Folders |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment