Skip to content

Instantly share code, notes, and snippets.

@danhigham
Created March 31, 2020 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danhigham/0ada789859e1c389f2884d9e0077f12f to your computer and use it in GitHub Desktop.
Save danhigham/0ada789859e1c389f2884d9e0077f12f to your computer and use it in GitHub Desktop.
#!/bin/bash
s3cmd ls -r $1/ | while read -r line;
do
createDate=`echo $line|awk {'print $1" "$2'}`
createDate=`date -d"$createDate" +%s`
olderThan=`date --date "7 days ago" +%s`
if [[ $createDate -lt $olderThan ]]
then
fileName=`echo $line|awk {'print $4'}`
if [[ $fileName != "" ]]
then
# aws s3 rm BUCKETNAME/$fileName
echo "Removing $fileName"
fi
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment