Skip to content

Instantly share code, notes, and snippets.

@aschober
Last active July 9, 2019 00:07
Show Gist options
  • Save aschober/3924cb5e20b258e290a558f52e01063f to your computer and use it in GitHub Desktop.
Save aschober/3924cb5e20b258e290a558f52e01063f to your computer and use it in GitHub Desktop.
Recursive AWS CLI S3 put-object-legal-hold Command
# command using s3 and s3api to recursively go through each file in a bucket and update the legal hold flag
# https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object-legal-hold.html
# https://stackoverflow.com/a/53696774
aws s3 ls s3://<bucket-location> --recursive > files.txt && cat files.txt | awk '{cmd="aws s3api put-object-legal-hold --legal-hold Status=OFF --bucket <bucket-location> --key "$4;system(cmd)}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment