Skip to content

Instantly share code, notes, and snippets.

@ByronScottJones
Created January 4, 2021 13:57
Show Gist options
  • Save ByronScottJones/5e87f99e1284fb7e39cd57f2ae59e347 to your computer and use it in GitHub Desktop.
Save ByronScottJones/5e87f99e1284fb7e39cd57f2ae59e347 to your computer and use it in GitHub Desktop.
Clean Folders
Days Folder
1 FolderPath
#!/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