Skip to content

Instantly share code, notes, and snippets.

@cablespaghetti
Last active October 6, 2023 06:52
Show Gist options
  • Save cablespaghetti/0df897c23565fc5822c3f37f2d15e22e to your computer and use it in GitHub Desktop.
Save cablespaghetti/0df897c23565fc5822c3f37f2d15e22e to your computer and use it in GitHub Desktop.
Find all files in S3 bucket with specific content-type
aws s3 ls s3://mybucket/ --recursive | awk '{print $4}' | parallel 'echo {}; if [ "$(aws s3api head-object --bucket mybucket --output json --key {} | jq .ContentType -r)" = "binary/octet-stream" ]; then echo {} >> dodgy.txt; fi'
cat dodgy.txt | grep png | parallel 'echo {}; aws s3 cp --content-type="image/png" --metadata-directive="REPLACE" s3://mybucket/{} s3://mybucket/{}'
@ulugbekrozimboyev
Copy link

Hello. I get following error when I run this script. (I replaced mybucket with my bucket name)

zsh: no such file or directory: echo {}; if [ "$(aws s3api head-object --bucket mybucket --output json --key {} | jq .ContentType -r)" = "binary/octet-stream" ]; then echo {} >> dodgy.txt; fi

[Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe

How can I fix it ?

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