-
-
Save lazd/4ac4296e4d7341d03462 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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 | |
# Find only files older than the specified date/time | |
echo "Deleting files in $DIR older than $DAYS days old" | |
find "$DIR"* -type f -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=( | |
"/path/to/old/videos" | |
) | |
# 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