Hint: s3cmd doesn't allow you do use wild-cards, but when you run the ls command, you can specify the beginning of an object name and it will only return objects starting with that. Make sure you know the output of your s3cmd ls command before you pass it to s3delmany.sh! There is no prompt asking if you're sure you want to delete the list, so get it right the first time! This will delete all objects under /img/. To pass s3delmany.sh a list of objects, you can run a command like this. The script works by taking a list of objects and running the delete command on each one. If you're using s3cmd and you placed s3delmany.sh in the /s3cmd/ directory, you should be able to use the script without modifying it. Make it executable: chmod 755 s3delmany.sh If you're not using s3cmd, change it to match the delete object command for that tool.ģ. Edit it with a text editor and make sure DELCMD is set correctly. Extract s3delmany.zip (you can put it wherever, but I put it in the same directory as s3cmd).Ģ. # we can delete each one by running the delete command.įor i in '$DLIST' do $DELCMD $iġ. # This basically strips the rest of the junk out soĭLIST=`awk 'BEGIN '` # that contains the full URL to the file. # If not using s3cmd, change $4 to match the column number # If not using s3cmd, change this to the delete command # and runs the delete command on each object. # except the column containing the objects, # Accepts a list of S3 objects, strips everything I mean come on, there are tools to automate this kind of stuff! So I created s3delmany.sh: #!/bin/sh Yea, there's no way I'm doing that for over 200 objects. This means I would need to get the full path to each object and delete them one by one. There is no way to do a wild-card delete. Unfortunately, the command line tool I'm using, s3cmd, does not allow me to delete multiple files at once. I've been doing some stuff at work using Amazon S3 to store files and during my testing I uploaded a ton of files that didn't need to be there. Please see the Amazon S3 Developer Guide for more information. Update: The Amazon S3 service API now allows for deleting multiple objects with one request (up to 1,000 objects per request).
0 Comments
Leave a Reply. |