Skip to content

Instantly share code, notes, and snippets.

@granolocks
Created August 31, 2012 03:02
Show Gist options
  • Select an option

  • Save granolocks/3548413 to your computer and use it in GitHub Desktop.

Select an option

Save granolocks/3548413 to your computer and use it in GitHub Desktop.
#!/bin/sh
# This checks that the specified file is less than 4 days old
# deletes files that are too old
for f in *.jpg
do
FILE=$f
MAXAGE=$(bc <<< '4*24*60*60') # seconds in a week
#MAXAGE=$(bc <<< '60') # seconds in a minute, for testing
## file age in seconds = current_time - file_modification_time.
FILEAGE=$(($(date +%s) - $(stat -c '%Y' "$FILE")))
test $FILEAGE -gt $MAXAGE && {
rm $FILE
}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment