Skip to content

Instantly share code, notes, and snippets.

@lazd
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save lazd/9441aeed47057403ca2a to your computer and use it in GitHub Desktop.

Select an option

Save lazd/9441aeed47057403ca2a to your computer and use it in GitHub Desktop.
A quick little script to delete files from of lists of folders older than a certain number of days
#!/usr/bin/env bash
# Delete files older than the given number of days in the given directory
# Usage: rmold $DAYS $DIR
# Example: rmold 7 temp
function rmold() {
DAYS=$1
DIR=$2
# Execute operation
echo "Deleting files in $DIR older than $DAYS days old"
find "$DIR" -mtime +$DAYS -exec rm -rf {} \;
# Check if command failed
if [ $? -eq 0 ]
then
echo "Files older than $DAYS deleted from $DIR"
else
echo "Failed to delete files in $DIR"
fi
}
# Define a list of folders to look at
FOLDERS=(
"/mnt/Data/Ryan-PC/Users/Ryan/Videos/TV/The Daily Show"
"/mnt/Data/Ryan-PC/Users/Ryan/Videos/TV/Conan"
)
# Use the new command
for FOLDER in "${FOLDERS[@]}"
do
rmold 7 "$FOLDER"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment