Skip to content

Instantly share code, notes, and snippets.

@nitisht
Last active April 30, 2019 01: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 nitisht/08248d7e510df74af29939cd98e21533 to your computer and use it in GitHub Desktop.
Save nitisht/08248d7e510df74af29939cd98e21533 to your computer and use it in GitHub Desktop.
mc json and jq playground

Delete all the objects in a bucket

while read -r key; do
    mc rm myminio/testb/${key}
done< <(mc ls --json myminio/testb | jq --raw-output '"\(.key)"')

Count objects in a bucket

mc ls -r --json qa-shore/multimedia | wc -l

List buckets

for i in $(mc --json ls alias/ | jq -r .key | grep '^bucket'); do mc ls alias/$i; done

Total object and their size

mc ls --json --recursive s3/ferenginar | jq .size | awk '{sum+=$1} END {print sum}' (for total size)

mc ls --json --recursive s3/ferenginar | jq .key | wc -l (for number of objects)
@harshavardhana
Copy link

harshavardhana commented Apr 19, 2019

mc ls --json --recursive s3/ferenginar | jq .size | awk '{sum+=$1} END {print sum}'

Better alternative human readable is

mc ls --json --recursive s3/ferenginar | jq .size | awk '{sum+=$1} END {print sum}' | numfmt --to=iec

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