Skip to content

Instantly share code, notes, and snippets.

@adatta02
Created February 9, 2013 00:12
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save adatta02/4743092 to your computer and use it in GitHub Desktop.
Save adatta02/4743092 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Usage: ./deleteOld "bucketname" "30 days"
s3cmd ls s3://$1 | while read -r line;
do
createDate=`echo $line|awk {'print $1" "$2'}`
createDate=`date -d"$createDate" +%s`
olderThan=`date -d"-$2" +%s`
if [[ $createDate -lt $olderThan ]]
then
fileName=`echo $line|awk {'print $4'}`
echo $fileName
if [[ $fileName != "" ]]
then
s3cmd del "$fileName"
fi
fi
done;
@parthmewada
Copy link

Hi,
What if i want to change the 30 Days to 10 or lesser days.

PS New to python scripting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment